2、key-验证各主机联通省密码

#!/bin/bash
#[----------]
#--------------------------------------------------------------
#Author:                jackie
#QQ:                    985848343@qq.com
#Date:                  2021-05-24_17:51:24
#FileName:              ssh-key-ubuntu.sh
#URL:                   https://blog.csdn.net/weixin_50504879
#Description:           The test script
#Copyright (C):         2021-05-24 All rights reserved
#--------------------------------------------------------------
dpkg -l expect   &> /dev/null
if  [ $?  ==  0 ];then
     echo  ""
else
     apt-get install -y expect  &> /dev/null
fi
SERVERS="
172.31.7.32
172.31.7.33
172.31.7.34
172.31.7.35
"
PASSWORD=1

auto_ssh_copy_id() {
    expect -c "set timeout -1;
        spawn ssh-copy-id $1;
        expect {
            *(yes/no)* {send -- yes\r;exp_continue;}
            *assword* {send -- $2\r;exp_continue;}
            eof        {exit 0;}
        }";
}

ssh_copy_id_to_all() {
    for SERVER in $SERVERS
    do
        auto_ssh_copy_id $SERVER $PASSWORD
    done
}

ssh_copy_id_to_all

posted @ 2023-02-09 02:48  Jackiezhu  阅读(19)  评论(0)    收藏  举报