生成密钥文件
ssh-keygen
安装expect
yum -y install expect
脚本
#!/bin/bash
#密码
password=Admin@123
for i in {11..20}
do
host="172.17.32.$i"
/usr/bin/expect <<-EOF
spawn ssh-copy-id root@$host
set timeout 300
expect {
"(yes/no)?" {
send "yes\n"
expect "*assword:" { send "$password\r"}
}
"*assword:" {
send "$password\n"
}
}
expect eof
EOF
done