- 生成秘钥对 192.168.1.8
[root@manager ~]# ssh-keygen -C 314833807@qq.com
- 将8服务器公钥推送到7服务器 192.168.1.8 —> 192.168.1.7
[root@manager ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.7
#将8服务器的root用户的公钥推送给7服务器的root用户
- 测试8服务器是否能免密码登录7服务器
[root@manager ~]# ssh 'root@172.16.1.7'
Last login: Mon Dec 2 11:03:45 2019 from m01
[root@backup ~]#
脚本推送多台服务器
[root@manager ~]# yum install sshpass -y
[root@manager ~]# sed -i '/^# StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config
[root@manager ~]# vim /scripts/key.sh
for i in 7 8
do
sshpass -p 123456 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.$i
done