您的位置:首页 > 其它

ssh登陆不需要密码(配置信任有关系)

2012-10-09 14:06 274 查看
A:192.168.2.127

B:192.168.2.128

1、生成密钥对

使用默认值,一路回车

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
b1:5f:58:b4:cf:9c:f1:33:4a:cb:8a:e6:84:87:09:bc root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|            .    |
|           . .   |
|        .   o .  |
|    .    o o + + |
|     o  S . ..=o.|
|      o +. .o o o|
|     E + o.  +   |
|        o.. .    |
|        oo .     |
+-----------------+

查看生成的密钥

[root@localhost ~]# ll .ssh/
total 8
-rw------- 1 root root 1675 Oct  9 11:59 id_rsa
-rw-r--r-- 1 root root  408 Oct  9 11:59 id_rsa.pub

3、配置需要同步的两台主机信任关系(避免ssh登陆需要密码)

分别从拷贝对方的id_rsa.pub到本机,

A主机:

scp root@192.168.2.128:/root/.ssh/id_rsa.pub /root

cat /root/id_rsa.pub >> /root/.ssh/authorized_keys

B主机:

scp root@192.168.2.127:/root/.ssh/id_rsa.pub /root

cat /root/id_rsa.pub >> /root/.ssh/authorized_keys

使用>>为了不影响原来可能存在和其它主机的信任关系

完成:

测试:

A主机:ssh 192.168.2.128看是否需要密码

本文出自 “notepad” 博客,请务必保留此出处http://sndapk.blog.51cto.com/5385144/1019679
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: