Password authentication in Python Paramiko fails, but same credentials work in SSH/SFTP client

Your server is using a keyboard-interactive authentication, not a simple password authentication.

Normally Paramiko is smart enough to fallback to the keyboard-interactive authentication, when the password authentication fails and the keyboard-interactive prompt has one field only (likely a password).

The problem is that your server behaves, as if the password authentication succeeded.

You can explicitly make Paramiko try the keyboard-interactive authentication using this code:

def handler(title, instructions, fields):
    if len(fields) > 1:
        raise SSHException("Expecting one field only.")
    return [password]

transport = paramiko.Transport('example.com') 
transport.connect(username="myuser")
transport.auth_interactive(username, handler)

Leave a Comment