在安装ansible之后,需要批量散发公钥,这里小小的写了一个脚本去散发公钥
关闭ssh的连接询问
在ansible机上编辑ssh的配置文件
sudo vim /etc/ssh/ssh_config
# StrictHostKeyChecking ask
StrictHostKeyChecking no
安装sshpass
centos
sudo yum install -y sshpass
ubuntu
sudo apt install -y sshpass
编辑ip列表
vim ip.txt
1.1.1.2
1.1.1.3
1.1.1.4
编写脚本
for ip in $(cat /root/ip.txt)
do
echo "=======Batch the file to the host $ip=========="
sshpass -p123456 ssh-copy-id $ip #-p选项后跟的是要拷贝主机的密码
echo -e "##########################END##########################\n"
done