【发布时间】:2015-05-13 00:49:06
【问题描述】:
我发现以下脚本可以让我无需手动输入所需密码即可访问服务器。 可悲的是,我不知道建立连接后如何执行命令:(
#!/usr/bin/expect -f
spawn ssh user@server
expect "assword:"
send "pw123\r"
interact
#the following is not executed anymore
cd /tmp/
cd /tmp/ 命令没有执行,有人知道怎么做吗? 我不在乎安全:) 基于密钥的身份验证不是一种选择。
编辑: 好的,我找到了适合我需求的解决方案:
#!/usr/bin/expect -f
spawn user@server
expect "assword:"
send "pw123\r"
expect "> " { send "cd /tmp\r" }
interact
expect "> " 必须像您的提示一样。
【问题讨论】:
-
我建议使用基于 SSH 密钥的身份验证。 digitalocean.com/community/tutorials/…