1.脚本
#!bin/bash
[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -f /root/.ssh/id_rsa -P "" &>/dev/null
while read line;do
ip=`echo $line | cut -d " " -f1`
username=`echo $line | cut -d " " -f2`
password=`echo $line | cut -d " " -f3`
expect <<EOF
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$ip
expect {
"yes/no" { send "yes\n";exp_continue}
"password" { send "$password\n"}
}
expect eof
EOF
done < /etc/ansible/host_ip.txt
通告: MySQL-MHA方案实践 – 瓜丢夏
通告: Ansible安装与自动化部署SSH密钥认证 – 瓜丢夏