【问题标题】:ssh expect script doesn't recognize connect stringssh 期望脚本无法识别连接字符串
【发布时间】:2015-10-07 19:14:14
【问题描述】:

我尝试了一个期望脚本,该脚本应该将 ssh 公钥复制到远程服务器并将其复制到适当的位置,以便您下次无需输入密码就可以 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':

基本上,问题在于脚本无法识别我试图设置的“您确定要继续连接是/否”字符串的行。

关于如何改进以使这些行匹配的任何建议?

谢谢

【问题讨论】:

    标签: ssh


    【解决方案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"
    

    ...对我来说很好用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2015-11-18
      • 2010-12-19
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多