2

pexpect モジュール pxssh を使用して、自分のサーバーにログインしようとしています。パスワードが拒否されます。問題が何であるかはわかっていると思いますが、それを修正する方法がわかりません。問題は、サーバーにログインするとウェルカム バナーが表示され (バナーの変更はオプションではありません)、pexpect が混乱することです。これが私のコードです:

import pxssh

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

私は「password:」を期待していますが、pxssh は original_prompt='[#$]' を期待しています。これらは記号であり、バナーでは「.」のカップルです。

どんな助けでも、私は感謝します。ありがとう

4

2 に答える 2

1

あなたの診断が正しいかどうかはわかりません。バナーが原因だとは思いませんが、間違ったプロンプトが原因である可能性は確かにあります。コードを見て確認してください。 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を直接使用しないのはなぜですか?

于 2013-04-05T07:23:09.943 に答える