12345678910111213141516171819
#!/bin/shpass=root123yum install expect -yecho "y"|ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsaiplist="k8s-master1 k8s-master2 k8s-master3"for i in ${iplist};doexpect -c "spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@${i}expect { "yes/no*" { send "yes"\r;exp_continue} "password*" { send "${pass}"\r;exp_continue} timeout { }}"doneexit