2013-04-04 95 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的?

相關問題