欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

expect 分发ssh key脚本

程序员文章站 2023-02-24 13:36:11
生成ssh key ......
 1 #!/usr/bin/expect
 2 if {$argc != 1} {
 3   send_user "usage:expect_sshkey.exp host"
 4   exit
 5 }
 6 
 7 #define var
 8 set host [lindex $argv 0]
 9 set password "123"
10 
11 #spawn
12 spawn ssh-copy-id -i /home/jp/.ssh/id_dsa.pub -p 52113 jp@$host
13 
14 #expect
15 expect {
16   "yes/no" {send "yes\r";exp_continue}
17   "*password" {send "$password\r";}
18 }
19 
20 expect eof
21 
22 exit -onexit {
23   send_user "good to you!\n"
24 }

 生成ssh key

 1 #!/usr/bin/expect
 2 #spawn
 3 spawn ssh-keygen -t dsa
 4 expect {
 5   "*key" {send "\r";exp_continue}
 6   "*passphrase" {send "\r";exp_continue}
 7   "*again" {send "\r"}
 8 }
 9 
10 expect eof
11 exit -onexit {
12   send_user "done!\n"}