ssh key一键自动化生成公钥私钥,并自动分发上百

作者:ssh key一键自动化生成公钥私钥,并自动分发上百 来源:未知 2022-06-21 03:28   阅读:

[root@web~]$vimfenfa_sshkey.sh#!/bin/shexpectssh-keygen.exp&>/dev/null./etc/init.d/functionsforip

[root@web ~]$ vim fenfa_sshkey.sh 
#!/bin/sh
expect ssh-keygen.exp &>/dev/null
. /etc/init.d/functions
for ip in 132 133
do
 #expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub 192.168.59.$ip  >/dev/null 2>&1
 expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub 192.168.59.$ip &>/dev/null
 if [ $? -eq 0 ];then
    action "192.168.59.$ip" /bin/true
 else
    action "192.168.59.$ip" /bin/false
 fi
done
[root@web ~]$ vim fenfa_sshkey.exp
#!/usr/bin/expect
if { $argc !=2 } {
 send_user "usage: expect fenfa_sshkey.exp file host
"
 exit
}
#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set password ""
#spawn scp /etc/hosts :/etc/hosts
#spawn scp -P $file os_admin@$host:$dir
#spawn ssh-copy-id -i  $file "-p  os_admin@$host"
spawn ssh-copy-id -i  $file "-p 22 root@$host"
expect {
        "yes/no"    {send "yes\r";exp_continue}
        "*password" {send "$password\r"}
}
expect eof

分享给小伙伴们:
ssh key一键自动化生成公钥私钥,并自动分发上百:如果本文侵犯了您的权利, 请联系本网立即做出处理,谢谢。
下一篇:没有了
ssh key一键自动化生成公钥私钥,并自动分发上百相关文章