ssh公钥认证配置:


本地(10.10.86.102)

[root@A ~]# ssh-keygen -t rsa -P ''

        密码为空,则输入密码时之间按ENTER回车

         -P '' ,表示密码为空,也可以不按-P,则要按三次回车


id_rsa        私钥

id_rsa.pub    公钥


不同类型的密钥

ssh-keygen -t dsa

ssh-keygen -t rsa(一般使用ssh的rsa密钥)

ssh-keygen -t rsal


在本地~/.ssh/目录下,生成id_rsa 和id_rsa.pub文件


把本地生成的id_dsa.pub(公钥)拷贝到你要访问的机器上并保存为authorized_keys.   

[root@A ~]# scp /root/.ssh/id_rsa.pub root@192.168.1.181:/root/.ssh/authorized_keys
root@
192.168.1.181's password:
id_rsa.pub                                    100%  223     0.2KB/s   00:00

     ps:拷贝到远端10.10.86.101时需要输入101上root用户的密码。

[root@A ~]# cat id_rsa.pub >> ~/.ssh/authorized.keys将.pub内容写入到authorized.keys中


将authorized_keys的权限改为600,~/.ssh目录权限改为700

[root@B ~]# chmod 600 /root/.ssh/authorized_keys

[root@B ~]# chmod 700 /root/.ssh


ssh root@10.10.86.101

    没有提示输入密码,直接登录,即OK

或者

[root@A ~]# ssh -l root 192.168.1.181
The authenticity of host 
'192.168.1.181 (192.168.1.181)' can't be established.
RSA key fingerprint is 00:a6:a8:87:eb:c7:40:10:39:cc:a0:eb:50:d9:6a:5b.
Are you sure you want to 
continue connecting (yes/no)? yes
Warning: Permanently added 
'192.168.1.181' (RSA) to the list of known hosts.
Last login: Thu Jul  3 09:53:18 2008 
from root