集群配置ssh免密

集群SSH免密登录脚本

#!/bin/bash
yum -y install expect
if [ -f /root/.ssh/id_rsa ]||[ -f id_rsa.pub ];then #判断是否有公密钥
  continue
else    #否则生产公密钥
/usr/bin/expect <<EOF  
spawn ssh-keygen -t dsa
expect ":" {send "\n;"}
#expect "exists" {send "y;"}
expect ":" {send "\n;"}
expect ":" {send "\n;"}
expect eof
EOF
fi
#read -ep "输入需要免密的IP,可以输入多个,用空格隔开:" IP
for i in 29 86 80 91 211 73 71 205 24 145 82 96 93 176 165 152
do
/usr/bin/expect <<EOF
spawn ssh-copy-id root@192.168.224.$i
expect "yes/no" {send "yes\n;exp_continue"}
expect "password" {send "r00tme321\n;"}
expect eof
EOF
done
  • for i in 29 86 80 91 211 73 71 205 24 145 82 96 93 176 165 152
    将数字改成实际的ip地址
  • spawn ssh-copy-id root@192.168.224.$i
    修改需要的用户名,要做哪个用户免密就用哪个username
  • expect “password” {send “r00tme321\n;”}
    修改对应username的password
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值