Skip to content

Authentication (publickey) failed. #1791

Closed

Description

@markditsworth

Nearly same issue as this previous one: #1135.

Paramiko version 2.7.2
Python version 3.7.3
Environment Raspberry Pi (Raspbian Buster)

ssh keys were generated in PEM format: ssh-keygen -t rsa -m PEM. Confirmed that I can ssh from the RPi to the target host with the private key from the command line.

>>> client = paramiko.SSHClient()
>>> pk = paramiko.RSAKey.from_private_key_file('/home/pi/.ssh/id_rsa')                
>>> paramiko.util.log_to_file('/home/pi/ssh_log.log')
>>> ip_address='192.168.1.114'
>>> port=22
>>> user='markd'
>>> client.connect(ip_address, username=user, port=port, pkey=pk, look_for_keys=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/paramiko/client.py", line 446, in connect
    passphrase,
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/paramiko/client.py", line 764, in _auth
    raise saved_exception
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/paramiko/client.py", line 664, in _auth
    self._transport.auth_publickey(username, pkey)
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/paramiko/transport.py", line 1580, in auth_publickey
    return self.auth_handler.wait_for_response(my_event)
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/paramiko/auth_handler.py", line 250, in wait_for_response
    raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.

Contents of /home/pi/ssh_log.log:

DEB [20201224-03:09:52.656] thr=1   paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.7.2
DEB [20201224-03:09:52.670] thr=1   paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_8.4
INF [20201224-03:09:52.671] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_8.4)
DEB [20201224-03:09:52.691] thr=1   paramiko.transport: kex algos:['curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ecdsa-sha2-nistp256', 'ssh-ed25519'] client encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] server encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] client mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] server mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
DEB [20201224-03:09:52.691] thr=1   paramiko.transport: Kex agreed: curve25519-sha256@libssh.org
DEB [20201224-03:09:52.692] thr=1   paramiko.transport: HostKey agreed: ssh-ed25519
DEB [20201224-03:09:52.692] thr=1   paramiko.transport: Cipher agreed: aes128-ctr
DEB [20201224-03:09:52.693] thr=1   paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20201224-03:09:52.693] thr=1   paramiko.transport: Compression agreed: none
DEB [20201224-03:09:53.018] thr=1   paramiko.transport: kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEB [20201224-03:09:53.020] thr=1   paramiko.transport: Switch to new keys ...
DEB [20201224-03:09:53.021] thr=2   paramiko.transport: Adding ssh-ed25519 host key for 192.168.1.114: b'e8da00c074f40ae87587b4cb2c1f2d3a'
DEB [20201224-03:09:53.022] thr=2   paramiko.transport: Trying SSH key b'e98158f6b3a46c0474fac8ce9e018874'
DEB [20201224-03:09:53.058] thr=1   paramiko.transport: userauth is OK
INF [20201224-03:09:56.527] thr=1   paramiko.transport: Authentication (publickey) failed.

Activity

  1. sagarkhushalani commented on Feb 25, 2021

    @sagarkhushalani

    Same issue; I can log in from command line, with the same key to the same host, but paramiko always gets an authentication failed.

    Some things to note:

    • In my case, the key was also generated by Paramiko
    • So far, I have tried versions 2.0.0, 2.3.0, and 2.7.2

    Log for v2.0.0 is below

    DEB [20210225-17:11:37.456] thr=1   paramiko.transport: starting thread (client mode): 0x6b0a198
    DEB [20210225-17:11:37.457] thr=1   paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.0
    DEB [20210225-17:11:37.497] thr=1   paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_8.4
    INF [20210225-17:11:37.497] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_8.4)
    DEB [20210225-17:11:37.540] thr=1   paramiko.transport: kex algos:['curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ecdsa-sha2-nistp256', 'ssh-ed25519'] client encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] server encrypt:['[email protected]', '[email protected]', 'aes256-ctr', '[email protected]', 'aes128-ctr'] client mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] server mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha1', '[email protected]', 'hmac-sha2-512'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
    DEB [20210225-17:11:37.540] thr=1   paramiko.transport: Kex agreed: diffie-hellman-group-exchange-sha256
    DEB [20210225-17:11:37.541] thr=1   paramiko.transport: Cipher agreed: aes128-ctr
    DEB [20210225-17:11:37.541] thr=1   paramiko.transport: MAC agreed: hmac-sha2-256
    DEB [20210225-17:11:37.542] thr=1   paramiko.transport: Compression agreed: none
    DEB [20210225-17:11:37.575] thr=1   paramiko.transport: Got server p (2048 bits)
    DEB [20210225-17:11:37.672] thr=1   paramiko.transport: kex engine KexGexSHA256 specified hash_algo 
    DEB [20210225-17:11:37.674] thr=1   paramiko.transport: Switch to new keys ...
    DEB [20210225-17:11:37.677] thr=2   paramiko.transport: Adding ecdsa-sha2-nistp256 host key for 10.44.25.102: b'487f0fe9a5f9745174963310b99161de'
    DEB [20210225-17:11:37.679] thr=2   paramiko.transport: Trying SSH key b'2c310662ec058457092b2d2fcbabfbee'
    DEB [20210225-17:11:37.711] thr=1   paramiko.transport: userauth is OK
    INF [20210225-17:11:37.750] thr=1   paramiko.transport: Authentication (publickey) failed.
    DEB [20210225-17:11:37.752] thr=2   paramiko.transport: Trying SSH agent key b'da3feaa362b6e67851f4b7b78851ee3e'
    DEB [20210225-17:11:37.779] thr=1   paramiko.transport: userauth is OK
    INF [20210225-17:11:37.815] thr=1   paramiko.transport: Authentication (publickey) failed.
    DEB [20210225-17:11:37.816] thr=2   paramiko.transport: Trying SSH agent key b'7eaef9820af612731af5bb459839a26c'
    DEB [20210225-17:11:37.843] thr=1   paramiko.transport: userauth is OK
    INF [20210225-17:11:37.878] thr=1   paramiko.transport: Authentication (publickey) failed.
    
  2. rowanz commented on Aug 11, 2021

    @rowanz

    I think I have the same issue when connecting to a new host -- Paramiko fails on 2.7.2 with something like

    DEBUG:paramiko.transport:starting thread (client mode): 0x990cdc18
    DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
    DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
    INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_8.2p1)
    DEBUG:paramiko.transport:kex algos:['curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256'] server key:['rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ssh-ed25519'] client encrypt:['[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', '[email protected]', '[email protected]'] server encrypt:['[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', '[email protected]', '[email protected]'] client mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
    DEBUG:paramiko.transport:Kex agreed: [email protected]
    DEBUG:paramiko.transport:HostKey agreed: ssh-ed25519
    DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
    DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
    DEBUG:paramiko.transport:Compression agreed: none
    DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
    DEBUG:paramiko.transport:Switch to new keys ...
    /usr/local/lib/python3.7/dist-packages/paramiko/client.py:837: UserWarning: Unknown ssh-ed25519 host key for 10.119.1.119: b'fd1cff78de01d51693019084fadad640'
      key.get_name(), hostname, hexlify(key.get_fingerprint())
    DEBUG:paramiko.transport:Trying SSH key b'1dc098011a80ec9cbcb3e2eb2a5de532'
    DEBUG:paramiko.transport:userauth is OK
    INFO:paramiko.transport:Authentication (publickey) failed.
    

    interestingly though, if I ssh to it first via the command line, and then try Paramiko, everything works! so not quite sure what the problem is...

  3. Trophime commented on Mar 12, 2022

    @Trophime

    I'm facing a similar issue on debian/Testing (bookworm)
    When using paramiko from Ubuntu/20.04 LTS to connect to debian/Testing (openssh 8.8p1) it fails
    But it works when on connecting to a debian/Stable (openssh 8.4p1)
    Hope it helps to find what is the problem...

  4. Trophime commented on Mar 12, 2022

    @Trophime

    I observe this behavior for 2.8.1 and 2.6.0

  5. Trophime commented on Mar 12, 2022

    @Trophime

    see: #1915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions