我有以下期望脚本来自动化 Ubuntu 上的 SSH 密钥生成。该脚本按预期运行,并生成密钥对,但需要 50-60 秒才能完成。这比我在空盒子上所期望的要多得多。
#!/usr/bin/expect --
eval spawn /usr/bin/ssh-keygen -t rsa
expect -re {Enter file in which to save the key (/root/.ssh/id_rsa): }
send -- "\r"
expect -re {Overwrite (y/n)? }
send -- "y\r"
expect -re {Enter passphrase (empty for no passphrase): }
send -- "\r"
expect -re {Enter same passphrase again:" }
send -- "\r"
puts "\nEnded expect script."
任何提示或提示要改变什么?
编辑:根据 Niall Byrne 的回答,我找到了以下期望脚本,该脚本快速且可处理首次密钥生成以及密钥重新生成(覆盖)。
#!/usr/bin/expect -f
set timeout -1
spawn /usr/bin/ssh-keygen -t rsa
expect {
"Enter file in which to save the key" {send -- "\r" ; exp_continue}
"Overwrite" {send -- "y\r" ; exp_continue}
"Enter passphrase (empty for no passphrase):" {send -- "\r" ; exp_continue}
"Enter same passphrase again:" { send -- "\r" ; exp_continue}
eof
}