简体   繁体   English

Python-Pxssh-尝试登录到远程服务器时出现密码拒绝错误

[英]Python - Pxssh - Getting an password refused error when trying to login to a remote server

I'm trying to use the pexpect module pxssh to log in into my one of my server. 我正在尝试使用pexpect模块pxssh登录到我的一台服务器中。 I get password refused. 我收到密码被拒绝。 I think I know what it is the problem, but can't figure out how to fix it. 我想我知道这是什么问题,但不知道如何解决。 The issue is that there is a welcome banner when I log in into the server(Changing the banner is not an option) and the pexpect get confuse. 问题是,当我登录服务器时有一个欢迎标语(更改标语不是一种选择),并且pexpect变得混乱。 Here is my code: 这是我的代码:

import pxssh

ssh = pxssh.pxssh()
ssh.login('192.168.1.10', 'username', 'password')

I'm expecting a 'password:', but pxssh is expecting original_prompt='[#$]'and those are symbols and in the banner the are couple of '.' 我期待一个'password:',​​但是pxssh期待的是original_prompt ='[#$]',它们是符号,并且在横幅中是一对'。

Any help, I will appreciate. 任何帮助,我将不胜感激。 Thanks 谢谢

This error came for ssh is lock.so open the terminals and execute that command 这个错误是因为ssh是lock.so打开终端并执行该命令

xxxx@toad:~$ rm .ssh/known_hosts

remove the known_hosts 删除known_hosts

another options is you login in windows means check command prompt. 另一个选择是您在Windows中登录意味着检查命令提示符。 if you try to login in windows means use for pexpect 如果您尝试在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 uses the shell prompt to synchronize output from the remote host. pxssh使用shell提示符来同步远程主机的输出。

In order to make this more robust it sets the shell prompt to something more unique than just $ or #. 为了使其更加健壮,它将shell提示设置为比$或#更独特的内容。 This should work on most Borne/Bash or Csh style shells. 这应该适用于大多数Borne / Bash或Csh样式的shell。 Refer http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection-with-python/ 请参阅 http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection-with-python/

I don't know if you are right on your diagnostic, I don't think the banner can cause that but a wrong prompt can do it for sure. 我不知道您的诊断是否正确,我不认为横幅会导致这种情况,但是可以肯定地使用了错误的提示。 Look at the code to be sure. 查看代码以确保。 http://www.opensource.apple.com/source/lldb/lldb-69/test/pexpect-2.4/pxssh.py http://www.opensource.apple.com/source/lldb/lldb-69/test/pexpect-2.4/pxssh.py

Especially that part: 特别是那部分:

 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')

Disclaimer: this is not my code but Pxssh code. 免责声明:这不是我的代码,而是Pxssh代码。 Why not using paramiko ( http://www.lag.net/paramiko/ ) or pexpect directly? 为什么不使用的paramiko( http://www.lag.net/paramiko/ )或直接Pexpect的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM