#!/bin/bash
#[----------]
#--------------------------------------------------------------
#Author: jackie
#QQ: [email protected]
#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
标签:24,联通,主机,ssh,key,172.31,copy,id,expect
From: https://www.cnblogs.com/zikang/p/17103934.html