一,在test1主机里的用户
运行 ssh-keygen -t rsa
结果如下
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bob/.ssh/id_rsa):
Created directory '/home/bob/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bob/.ssh/id_rsa.
Your public key has been saved in /home/bob/.ssh/id_rsa.pub.
The key fingerprint is:
b7:99:2b:88:0b:02:1d:a0:d5:68:bd:bb:00:86:d2:d1 bob@
会在bob用户目录~/.ssh /产生两个文件,id_rsa,id_rsa.pub
其中id_rsa 为私钥,id_rsa.pub为公钥
二,把id_rsa.pub 文件拷贝到test2主机的用户目录下,如root目录下
cat id_rsa.pub >~/.ssh/authorized_keys
就可以了
这样test1主机的用户就可以通过ssh而不用密码登陆 test2主机
三、 现在我们把test1主机的内容copy到test2主机时就不需要提示密码了。
scp /root/a.txt root@test2:/root/ 不需要输入密码
如果要用其他用户去验证的话,那么在步骤二中我们就需要把公钥copy到对应用户的.ssh/authorized_keys即可 。
四 、通过上面三个步骤的实现 ,当我们写脚本来使用scp来copy文件时就很方便了
阅读(3061) | 评论(0) | 转发(2) |