我尝试了一个预期脚本,该脚本应该将ssh公钥复制到远程服务器并将其复制到位,这样您就可以进入它而无需输入在下次密码中。
我试图首次允许主机连接,以期待有关无法识别的主机密钥的投诉:
#!/usr/bin/expect -f
set PUB "~/.ssh/id_rsa.pub"
spawn scp $PUB openplatform@100.114.114.106:
expect {
"(Are you sure you want to continue connecting yes/no)?" { send "yes\r"; exp_continue }
password: {send secret!\r; exp_continue}
}
expect "password: "
send "secret!\r"
这是我实际运行脚本时发生的事情:
#./bin/ssh-login.ssh
spawn scp ~/.ssh/id_rsa.pub openplatform@100.114.114.106:
spawn ssh openplatform@100.114.116.106 /bin/mkdir .ssh && /bin/chmod 700 .ssh && /bin/cat id_rsa.pub >> .ssh/authorized_keys && /bin/chmod 600 .ssh/authorized_keys
The authenticity of host '100.114.116.106 (100.114.116.106)' can't be established.
RSA key fingerprint is 3b:04:73:25:24:f3:aa:99:75:a7:98:62:5d:dd:1b:38.
Are you sure you want to continue connecting (yes/no)? secret!
Please type 'yes' or 'no':
基本上问题在于我尝试设置的行以期待"您确定要继续连接是/否"脚本无法识别字符串。
有关我如何改进这些以使这些行匹配的任何建议?
由于
答案 0 :(得分:1)
你的脚本中有一个拼写错误 - “你确定......”行的开头括号应该在“是/否”之前,而不是在开头。固定版本:
#!/usr/bin/expect -f
set PUB "~/.ssh/id_rsa.pub"
spawn scp $PUB openplatform@100.114.114.106:
expect {
"Are you sure you want to continue connecting (yes/no)?" { send "yes\r"; exp_continue }
password: {send secret!\r; exp_continue}
}
expect "password: "
send "secret!\r"
......对我来说很好用