每日一shell 批量快速推送key到远程主机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每日一shell 批量快速推送key到远程主机相关的知识,希望对你有一定的参考价值。
作用:快速自动生成密钥,并批量推送到远程主机,适用于为ansible环境批量推送key
#!/bin/bash
keypath=/root/.ssh
iplist=/root/ip.txt
[[ -e ${iplist} ]] && > ${iplist}
for i in `seq 81 91`
do
echo -E "192.168.118.$i" >> ${iplist}
ssh-keyscan 192.168.118.$i >> ${keypath}/known_hosts
done
cat ${iplist}
[ -d {keypath} ] || mkdir -p ${keypath}
rpm -q expect &> /dev/null || yum install expect -y
[[ -e ${keypath}/id_rsa.pub ]] || ssh-keygen -t rsa -f ${keypath}/id_rsa -P ""
password=u7wtiYTl0
while read ip;do
expect << EOF
set timeout 5
spawn ssh-copy-id $ip
expect {
“yes/no” { send "yes
";exp_continue }
"password" { send "$password
" }
}
expect off
EOF
done < ${iplist}
以上是关于每日一shell 批量快速推送key到远程主机的主要内容,如果未能解决你的问题,请参考以下文章