自动化免密脚本

先安装 expect bash

yum install expect服务器

 

 

#!/bin/bashssh

#ide

#列出要免密的服务器spa

SERVERS="192.168.1.1 192.168.1.2 192.168.1.3"it

#服务器密码class

PASSWORD=123456配置

 

#模拟配置免密过程循环

auto_ssh_copy_id() {密码

#设置不超时

expect -c "set timeout -1;

#执行ssh-copy-id命令

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

相关文章
相关标签/搜索