您的位置:首页 > 运维架构 > Shell

一个shell脚本实现linux集群所有机器免密钥登录

2017-08-23 19:45 375 查看
1,先安装expect

yum install expect

2.生成密钥

ssh-keygen(注,一路回车,不用管)

3.修改host文件 /etc/hosts

4.编写shell脚本

#!/bin/bash
SERVERS="flux01 flux02 flux03 flux04 flux05  flux06  flux07  flux08  flux09"
PASSWORD=root
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell linux 免密钥
相关文章推荐