1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #!/bin/sh
pass=root123 yum install expect -y echo "y"|ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa iplist="k8s-master1 k8s-master2 k8s-master3"
for i in ${iplist};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 "${pass}"\r;exp_continue} timeout { } }" done exit
|