|
A:192.168.2.127
B:192.168.2.128
1、生成密钥对
使用默认值,一路回车
- [iyunv@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 . |
- +-----------------+
查看生成的密钥
- [iyunv@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/id_rsa.pub /root
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
B主机:
scp root@192.168.2.127:/root/id_rsa.pub /root
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
使用>>为了不影响原来可能存在和其它主机的信任关系
完成:
测试:
A主机:ssh 192.168.2.128看是否需要密码
注:
对方的id_rsa.pub一定不能存在于本机的ssh用户家目录下的.ssh目录中!!!
可以不存在!
如果A主机的存在于B主机的.ssh下,B主机登陆A主机需要密码,失去信任关系!
|
|
|
|
|
|
|