簡體   English   中英

Python-Pxssh-嘗試登錄到遠程服務器時出現密碼拒絕錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM