通过pexpect进行简单的SSH访问?

问题描述

我试图通过遵循此处提供的示例来简化SSH访问。

https://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/

代码看起来很简单,但是我仍然无法使它正常工作。

>>> import pexpect
>>> 
>>> hostname = 'bandit.labs.overthewire.org'
>>> username = 'bandit0'
>>> password = 'bandit0'
>>> port = '2220'
>>> 
>>> p = pexpect.spawn(f'ssh {username}@{hostname} -p {port} uname -a')
>>> print(p.before)
None
>>> 

我一直在获取None而不是实际的uname -a输出。

此代码有什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)