配置过程
- 登录服务器A
- rm -rf ~/.ssh
- 建立ssh相关目录: mkdir ~/.ssh
- 设置ssh的权限: chmod 700 ~/.ssh
- 生成RSA公钥
ssh-keygen -t rsa (请一直回车,直至提示结束
[root@test .ssh]# 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:
e5:22:0f:77:32:5c:c1:e8:55:c8:a3:f0:1a:13:f3:a0 root@test
The key’s randomart image is:
±-[ RSA 2048]----+
| +.o. |
| = . *. |
| . O oo. |
| E o.=+ |
| o+S o |
| .= = |
| . |
| |
| |
±----------------+
- 将公钥(名为id_rsa.pub文件)追加到认证文件(名为authorized_keys文件)中:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- 设置认证文件的权限
chmod 600 ~/.ssh/authorized_keys
- 在服务器B 重复上面的操作到5
cp id_rsa.pub id_rsa.pub1 scp id_rsa.pub1 192.168.56.160:/root/.ssh
9 服务器A
cat id_rsa.pub1 >>authorized_keys scp authorized_keys 192.168.56.170:/root/.ssh
- 测试
服务器A:
[root@test .ssh]# ssh 192.168.56.170 Last login: Fri Sep 28 09:41:41
2018 from 192.168.56.1
服务器B:
[root@test2 .ssh]# ssh 192.168.56.160 Last login: Fri Sep 28 09:37:55
2018 from 192.168.56.1