美文网首页
编写ssh互信脚本

编写ssh互信脚本

作者: zymnanako | 来源:发表于2018-06-17 06:57 被阅读0次
  1. 安装expect
sudo yum install -y tcl tk expect
  1. 编写exp文件audt.exp
#!/usr/bin/expect

set timeout 10
set user_hostname [lindex $argv 0]
set password [lindex $argv 1]

spawn ssh-copy-id $user_hostname
expect {
        "(yes/no)?"
        {
                send "yes\n"
                expect "*password: " { send "$password\n" }
        }
        "*password: " { send "$password\n" }
}

expect eof
  1. 编写批量脚本batch.sh
#!/bin/bash

ip=`echo -n "$(seq -s "," 10 13),30" | xargs -d "," -i echo 192.168.10.{}`
password="password"
#user_host=`awk '{print $3}' /home/vagrant/.ssh/id_rsa.pub`

for i in $ip;do
        /home/vagrant/auto.exp root@$i $password &
        ssh vagrant@$i "echo $i ok"
done

相关文章

网友评论

      本文标题:编写ssh互信脚本

      本文链接:https://www.haomeiwen.com/subject/uubieftx.html