自动化部署SSH密钥认证

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


「 文章如果对你有帮助,请点个赞哦^^ 」 

1+

这篇文章有 2 条评论

评论关闭。