yum -y install expect // 自动交互服务 // 生产公钥 ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa // 修改ip和主机名成需要免密的机器 for i in 192.168.178.100 192.168.178.140 k8s_master k8s_node2;do expect -c " spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$i expect { \"*yes/no*\" {send \"yes\r\"; exp_continue} \"*password*\" {send \"password\r\"; exp_continue} \"*Password*\" {send \"password\r\";} } " done
验证测试:
[root@k8s_node1 ~]# ssh 192.168.178.100
Last login: Tue May 11 19:48:50 2021 from k8s_node1
[root@k8s_master ~]# ssh k8s_node2
Last login: Tue May 11 19:48:27 2021 from 192.168.178.130