1。 分别从A和B上登录作为root后运行
#ssh-keygen -t rsa
目的是简单地在/root下创建目录.ssh,当提示输入 passphase时打入两次回车。这将生成下面这两个文件:
/root/.ssh/id_rsa.pub
2。 先测试一下,从A登录作为root,输入
#ssh B
会要求提示
3。 现在从A登录作为root,运行
#scp /root/.ssh/id_rsa.pub root@[B:ip]:/root/.ssh/authorized_keys
文件名必须不能弄错。
4。现在再从A运行
#ssh B
//则不需要密码了,反过来要从B ssh到A,需要在B上执行ssh-keygen -t rsa 命令,然后将生成的文件scp到A上去
实例:
[root@test2 ~]# 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:
aa:79:22:71:fb:7d:01:cd:2a:c2:49:18:5e:9c:c8:b9 root@test2
[root@test2 ~]# scp /root/.ssh/id_rsa.pub root@test1:/root/.ssh/authorized_keys
root@test1's password:
id_rsa.pub 100% 220 0.2KB/s 00:00
[root@test2 ~]# ssh test1
Last login: Tue Oct 6 11:09:44 2009 from 17.red-88-22-6.staticip.rima-tde.net
[root@test1 ~]#