ssh免密验证,shell批量设置

 

ssh免密验证,shell批量设置

 

#ssh免密验证,shell自动设置
echo '#!/bin/sh
. /etc/init.d/functions
[[ -f /usr/bin/expect ]] || { echo "install expect";yum install expect -y; } #若没expect则安装
[ $? = 0 ] || { echo "expect安装失败";exit; } #安装失败则退出
PUB=/'`whoami`'/.ssh/id_dsa.pub #公钥路径
[[ -f $PUB ]] || { ssh-keygen -t dsa -P "" -f /'`whoami`'/.ssh/id_dsa>/dev/null 2>&1; } #若没公钥则生成

USER=root   #登录用户
PASS=123321 #登录密码
#expect自动交互
function EXP() {
/usr/bin/expect << EOF
set timeout 5
spawn /usr/bin/ssh-copy-id -i $PUB  $USER@$n
expect {
        "*yes/no*" { send "yes\r";exp_continue }
        "password:" { send "$PASS\n";exp_continue } 
        eof { exit }
        }
EOF
}
#
for n in $*
do
  EXP >/dev/null 2>&1
  echo $n hostname >/dev/null 2>&1
  [[ $? == 0 ]] && action "========$n" /bin/true || action "========$n" /bin/false
done
'>./ssh.sh
##################以上是生成shell文件ssh.sh##################

#hosts设置
echo '
192.168.58.21   controller1
192.168.58.22   controller2
192.168.58.23   controller3
'>>/etc/hosts

#执行shell文件,ssh批量认证
sh ./ssh.sh controller1 controller2 controller3

 

转载于:https://www.cnblogs.com/elvi/p/7681779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值