实现SSH无密码登陆
时间:2006-10-31 来源:aoxer
这种情况适合于内网的两台机器使用的方便,慎用。
如果想从host1不用密码登陆到host2,那么如下步骤:
首先建立本机的公私密钥
[root@host1 root]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
9b:40:4c:a1:9c:d0:10:d6:bf:1b:5f:0d:8c:6b:0c:0a root@host1
[root@host1 root]# 注意不要输入passphrase 然后将公钥文件传送到需要登陆的服务器
[root@host1 root]# scp .ssh/id_dsa.pub root@host2:id_dsa.pub
root@host2's password:
id_dsa.pub 100% |*****************************| 600 00:00
登陆那台服务器
CODE[root@host1 root]# ssh -v root@host2 将刚才的公钥文件内容添加到用户的.ssh目录下的authorized_keys文件中
CODE
[root@host2 root]# cat id_dsa.pub >> /root/.ssh/authorized_keys
然后更改该文件权限
CODE
[root@host2 root]# chmod 600 /root/.ssh/authorized_keys
退出
CODE
[root@host2 root]# exit
Connection to host2 closed.
[root@host1 root]#
再次登陆即不再需要密码了
CODE[root@host1 root]# ssh host2
Last login: Wed Nov 17 17:55:34 2004 from 61.129.xxx.xxx
[root@host2 root]#
[root@host1 root]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
9b:40:4c:a1:9c:d0:10:d6:bf:1b:5f:0d:8c:6b:0c:0a root@host1
[root@host1 root]# 注意不要输入passphrase 然后将公钥文件传送到需要登陆的服务器
[root@host1 root]# scp .ssh/id_dsa.pub root@host2:id_dsa.pub
root@host2's password:
id_dsa.pub 100% |*****************************| 600 00:00
登陆那台服务器
CODE[root@host1 root]# ssh -v root@host2 将刚才的公钥文件内容添加到用户的.ssh目录下的authorized_keys文件中
CODE
[root@host2 root]# cat id_dsa.pub >> /root/.ssh/authorized_keys
然后更改该文件权限
CODE
[root@host2 root]# chmod 600 /root/.ssh/authorized_keys
退出
CODE
[root@host2 root]# exit
Connection to host2 closed.
[root@host1 root]#
再次登陆即不再需要密码了
CODE[root@host1 root]# ssh host2
Last login: Wed Nov 17 17:55:34 2004 from 61.129.xxx.xxx
[root@host2 root]#
相关阅读 更多 +