编写shell脚本实现批量推送公钥
推送主机的密码要相同!
vim ~/.ssh/pushs.sh
#!/bin/sh
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
host1=`cat /etc/ansible/roles/hosts | awk -F " " '{print $1}' | grep '^172'`
for i in $host1;
do
command1="scp ~/.ssh/id_rsa.pub root@$i:~/.ssh/id_rsa.pub"
password="123"
/usr/bin/expect -c "
spawn ssh-copy-id root@$i
expect {
\"*(yes/no)\" { send \"yes\r\";exp_continue }
\"*password\" { send \"$password\r\";exp_continue }
}
expect eof"
done
sh ~/.ssh/pushs.sh