Python pexpect.pxssh.ExceptionPxssh: 密码被拒绝

Python pexpect.pxssh.ExceptionPxssh: password refused

以下凭据是正确的。

wolf@linux:~$ sshpass -p bandit0 ssh bandit0@bandit.labs.overthewire.org -p 2220
This is a OverTheWire game server.

但是它不适用于 Python pexpect.pxssh

>>> from pexpect import pxssh
>>> s = pxssh.pxssh()
>>> hostname = 'bandit.labs.overthewire.org'
>>> username = 'bandit0'
>>> password = 'bandit0'
>>> port = '2220'
>>> s.login(hostname, username, password, port)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pexpect/pxssh.py", line 402, in login
    raise ExceptionPxssh('password refused')
pexpect.pxssh.ExceptionPxssh: password refused
>>> 

您的错误源于您为方法提供的位置参数 pexpect.pxssh.pxssh.login

根据文档,该方法的前四个位置参数是:

server, username=None, password='', terminal_type='ansi'

因此,当您调用 s.login(hostname, username, password, port) 时,您会将 terminal_type 设置为 port-number。

如果您将最后一个参数更改为 keyword-argument,端口将被正确设置:

s.login(hostname, username, password, port=port)