侧边栏壁纸
博主头像
AllInOne博主等级

随风来,随风去

  • 累计撰写 45 篇文章
  • 累计创建 27 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

Linux批量配置ssh免密(实战篇)

AllInOne
2024-05-29 / 0 评论 / 0 点赞 / 124 阅读 / 129 字
温馨提示:
点赞-关注-不迷路。

安装依赖

sudo yum install expect

相关脚本

#!/bin/bash
if [ ! -f ~/.ssh/id_rsa ];then
 ssh-keygen -t rsa
else
 echo "id_rsa has created ..."
fi
 
while read line
  do
    ip=`echo $line | cut -d " " -f 1`
    user="bigdata"
    passwd="xxx"
    expect <<EOF
      set timeout 10
      spawn ssh-copy-id -i /home/bigdata/.ssh/id_rsa.pub $user@$ip
      expect {
        "yes/no" { send "yes\n";exp_continue }
        "password" { send "$passwd\n" }
      }
      expect "password" { send "$passwd\n" }
EOF
  done <  hostlist.txt

对应机器文件

vim hostlist.txt
bigdata1
bigdata2
bigdata3
bigdata4
bigdata5
bigdata10
bigdata11
bigdata12
bigdata13
bigdata14
0

评论区