美文网首页
实验:让多台主机实现基于key验证

实验:让多台主机实现基于key验证

作者: Simon_Ye | 来源:发表于2020-03-11 13:01 被阅读0次
    #!/bin/bash
    #
    dir=/root/.ssh
    scrfile=$dir/id_rsa
    pubfile=$dir/id_rsa.pub
    login_password='abcdefg'
    localip=172.16.0.11
    
    rpm -q expect &> /dev/null || yum install expect -y &> /dev/null
    
    [ -d $dir ] || mkdir $dir
    
    if [ ! -f $scrfile -o ! -f $pubfile ];then
            ssh-keygen -f $scrfile -P "" &> /dev/null
            expect <<-EOF
            spawn ssh-copy-id -i $pubfile $localip
            expect {
                    "yes/no" { send "yes\n";exp_continue }
                    "password" { send "$login_password\n" }
            }
            expect eof
            EOF
    fi
    
    while read ipaddr;do
            expect <<-EOF
            set timeout 10
            spawn scp -pr $dir $ipaddr:/root/
            expect {
                    "yes/no" { send "yes\n";exp_continue }
                    "password" { send "$login_password\n" }
            }
            expect eof
            EOF
    done < /root/ipaddr.txt
    

    相关文章

      网友评论

          本文标题:实验:让多台主机实现基于key验证

          本文链接:https://www.haomeiwen.com/subject/iyaqjhtx.html