yum -y install expect ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa for i in 192.168.1.11 192.168.1.12 192.168.1.13 192.168.1.14 k8s-master1 k8s-master2 k8s-master3 k8s-node1;do expect -c " spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$i expect { "*yes/no*" {send "yes "; exp_continue} "*password*" {send "Flyaway.123 "; exp_continue} "*Password*" {send "Flyaway.123 ";} } " done