linux shell脚本批量免密认证
1. 提前在跳板机上上生成密钥。
2. 在脚本同级目录闯将hosts文件,文件中记录主机的IP地址,一个IP一行。
3. 创建 aoto_ssh.sh 脚本,脚本中password变量填写机器的密码。
#!/bin/bash
password='主机密码'
cat hosts | while read ip
do
echo "dealwith hosts:" $ip
expect << EOF
set timeout 10
spawn ssh-copy-id $ip
expect {
"yes/no" {
send "yes\n"
exp_continue
}
"password:" {
send "$password"
interact
send "\n"
}
}
expect eof
EOF
echo "\ndealend hosts:" $ip
done
结束!!!