我正在编写一个GUI程序来生成和监视SSH隧道,这些用户被吓得不敢使用命令行。在
不幸的是,有问题的服务器非常严格。通过rsasecurid令牌的双因素身份验证是唯一官方认可的打开SSH连接的方式。不允许使用无密码的RSA公钥/私钥身份验证。在
因此,我的程序有必要从文本输入框中读取密码并将其发送给SSH子进程。不幸的是,ssh
花了很大的力气来确保密码只来自真正的键盘。在
我强烈建议不要使用第三方模块。我知道paramiko和pexpect(它们都是作为类似问题的可能解决方案而提出的),但是试图向我的用户解释如何从源代码安装Python模块太让人头疼了。在
那么:如何使用标准pythonsubprocess
模块向ssh子进程发送密码?有没有办法让子进程以为我在使用TTY?是否可以使用SSH_ASKPASS来读取我的程序?在
也允许使用其他标准库模块(例如,os
模块的低级命令)。在
最后,我能够使用pty模块通过伪终端控制ssh。我在
pexpect
中编写了一个解决方案,然后通过查看pexpect源代码并得到this StackOverflow answer的帮助,我就可以知道该怎么做了。下面是相关代码的摘录(作为对象方法的一部分执行;因此引用了self
)。在相关问题 更多 >
编程相关推荐