使用期望向ssh传递密码 [英] Using expect to pass a password to ssh
本文介绍了使用期望向ssh传递密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用期望向ssh连接发送密码。
How can I use expect to send a password to an ssh connection.
说密码是p @ ssword
,ssh命令是
ssh me@127.0.0.1
say the password was p@ssword and the ssh command was ssh me@127.0.0.1
我该怎么办,让它在输入密码时输入密码
What would I do with expect to a make it input the password when it says
me@127.0.0.1的密码:
?
me@127.0.0.1's password:
?
使用SSH密钥对的正确操作不是选项,因为我将不得不使用ssh(scp)将密钥放在服务器上,这将要求一个密码。
The proper action of using an SSH key pair isn't an option because I would have to use ssh (scp) to put the key on the server, which would ask for a password.
推荐答案
我总是使用正确的解决方案,但我在其他情况下使用期望。
I always used the "proper" solution, but I used expect in other situations.
这里我发现以下建议:
#!/usr/local/bin/expect
spawn sftp -b cmdFile user@yourserver.com
expect "password:"
send "shhh!\n";
interact
这篇关于使用期望向ssh传递密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文