ssh 密钥认证,ssh scp无需输入密码的实现

经常在Linux间用scp命令传输文件,每次度需要输入对方机器的密码,非常麻烦。这种方式可以实现让双方自动通过密钥认证,无需手动输入密码:
 
1,Root登陆,在两边机器执行以下命令并一路回车,生成RSA私钥和公钥:
[root@ ~]# cd .ssh
[root@ .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
e7:ad:46:67:45:1a:df:da:cd:c7:32:e3:bf:76:8e:a9
 
2, 在两边机器查看/root/.ssh, 发现都生成两个文件:id_rsa ,id_rsa.pub, id_rsa为私钥,id_rsa.pub为公钥:
[root@ .ssh]# ll
total 32
-rw------- 1 root root 1675 Aug 10 22:09 id_rsa
-rw-r--r-- 1 root root  415 Aug 10 22:09 id_rsa.pub
-rw-r--r-- 1 root root  222 Aug  8 22:52 known_hosts
 
3,在两边机器的/root/.ssh/目录下分别建立authorized_keys文件,并将对方的公钥id_rsa.pub文件内容考到authorized_keys上,这样既可实现无需密码传输文件了。
 
4,如果多个机器,将其他机器的公钥文件内容追加到本机的authorized_keys文件中,既可实现本地向对方机器传输无需输入密码了。
 

你可能感兴趣的:(ssh,rsa,ssh-keygen,休闲,无需密码)