2013-04-04 57 views
1

我试图使用Pexpect的模块pxssh登录到我的我的服务器之一,当一个密码拒绝错误。我拒绝了密码。我想我知道这是什么问题,但无法弄清楚如何解决问题。问题是,当我登录到服务器时有一个欢迎横幅(更改横幅不是一个选项),并且pexpect会变得混乱。这里是我的代码:的Python - Pxssh - 开始尝试登录到远程服务器

import pxssh 

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

我期待一个“密码:”,但pxssh期待original_prompt =“[#$]”那些是符号和旗帜是情侣“”

任何帮助,我会很高兴。由于

回答

2

来到了SSH此错误是lock.so打开终端,并执行该命令

[email protected]:~$ rm .ssh/known_hosts 

删除known_hosts中

另一个选项是在Windows登录,就意味着检查命令提示符。 如果您尝试在Windows登录意味着使用Pexpect的

child = pexpect.spawn('ssh [email protected] -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风格的炮弹。 参照 http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection-with-python/

0

我不知道你就在您的诊断,我不认为横幅可能会导致,但一个错误的提示可以肯定地做到这一点。看看代码是肯定的。 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代码。 为什么不使用的paramikohttp://www.lag.net/paramiko/)或直接Pexpect的?

相关问题