[英]Python - Pxssh - Getting an password refused error when trying to login to a remote server
我正在尝试使用pexpect模块pxssh登录到我的一台服务器中。 我收到密码被拒绝。 我想我知道这是什么问题,但不知道如何解决。 问题是,当我登录服务器时有一个欢迎标语(更改标语不是一种选择),并且pexpect变得混乱。 这是我的代码:
import pxssh
ssh = pxssh.pxssh()
ssh.login('192.168.1.10', 'username', 'password')
我期待一个'password:',但是pxssh期待的是original_prompt ='[#$]',它们是符号,并且在横幅中是一对'。
任何帮助,我将不胜感激。 谢谢
这个错误是因为ssh是lock.so打开终端并执行该命令
xxxx@toad:~$ rm .ssh/known_hosts
删除known_hosts
另一个选择是您在Windows中登录意味着检查命令提示符。 如果您尝试在Windows中登录,则意味着要使用pexpect
child = pexpect.spawn('ssh tiger@172.16.0.190 -p 8888')
child.logfile = open("/tmp/mylog", "w")
print child.before
child.expect('.*Are you sure you want to continue connecting (yes/no)?')
child.sendline("yes")
child.expect(".*assword:")
child.sendline("tiger\r")
child.expect('Press any key to continue...')
child.send('\r')
child.expect('C:\Users\.*>')
child.sendline('dir')
child.prompt('C:\Users\.*>')
pxssh使用shell提示符来同步远程主机的输出。
为了使其更加健壮,它将shell提示设置为比$或#更独特的内容。 这应该适用于大多数Borne / Bash或Csh样式的shell。 请参阅 http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection-with-python/
我不知道您的诊断是否正确,我不认为横幅会导致这种情况,但是可以肯定地使用了错误的提示。 查看代码以确保。 http://www.opensource.apple.com/source/lldb/lldb-69/test/pexpect-2.4/pxssh.py
特别是那部分:
elif i==2: # password prompt again
# For incorrect passwords, some ssh servers will
# ask for the password again, others return 'denied' right away.
# If we get the password prompt again then this means
# we didn't get the password right the first time.
self.close()
raise ExceptionPxssh ('password refused')
免责声明:这不是我的代码,而是Pxssh代码。 为什么不使用的paramiko( http://www.lag.net/paramiko/ )或直接Pexpect的 ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.