使用 expect 将密码传递给 ssh [英] Using expect to pass a password to ssh

查看:23
本文介绍了使用 expect 将密码传递给 ssh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 expect 向 ssh 连接发送密码.

How can I use expect to send a password to an ssh connection.

说密码是p@ssword并且 ssh 命令是ssh 我@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.

推荐答案

我总是使用正确"的解决方案,但我在其他情况下使用了expect.

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!
";
interact

这篇关于使用 expect 将密码传递给 ssh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆