批量分发SSH秘钥

#!/usr/bin/expect
# filename: distribute_key.exp
if [ $argc != 2 ]{
  send_user "usage: expect expect.exp file host\n"
  exit
}
set file [lindex $argv 0]
set host [lindex $argv 1]
set password "123456"
spawn ssh-copy-id -i $file "-p 22 root@$host"
expect {
  "yes/no" {send "yes\r";exp_continue}}
  "*password" {send "$password\r"}
}
expect eof


#!/bin/bash
# filname:distribute_key.sh
for n in 128 129 130
do
  expect distribute_key.exp ~/.ssh/id_dsa.pub 192.168.33.$n
done

测试;
ssh-keygen -t dsa -P "" -f ~/.ssh/id_dsa >/dev/null 2>&1
sh distribute_key.sh

posted @ 2017-09-07 14:05  盛碗米饭  阅读(175)  评论(0编辑  收藏  举报