Skip to content

Authentication failed with public key #1135

Closed

Description

@sprenge

The remote side accepts the connection using the public key but paramiko still gives an error. Seems to be a bug in paramiko==2.4.0 (ubuntu 16.04, python 3)

Stack trace :
File "/usr/local/lib/python3.5/dist-packages/pysftp/init.py", line 143, in init
self._transport.connect(**self._tconnect)
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1205, in connect
self.auth_publickey(username, pkey)
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1450, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/usr/local/lib/python3.5/dist-packages/paramiko/auth_handler.py", line 226, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.

Activity

  1. sprenge commented on Dec 17, 2017

    @sprenge
    Author

    Remark, I can ssh to the host without any problem, without specifying a password

  2. holmanb commented on Mar 27, 2018

    @holmanb

    Same issue, same version. I can ssh from the command line, but Paramiko fails using the rsa key. Any word on this?
    Paramiko==2.4.0 (CentOS 7, python 3.4).
    Stack Trace:

     File "/usr/lib/python3.4/site-packages/paramiko/client.py", line 424, in connect
        passphrase,
      File "/usr/lib/python3.4/site-packages/paramiko/client.py", line 714, in _auth
        raise saved_exception
      File "/usr/lib/python3.4/site-packages/paramiko/client.py", line 691, in _auth
        self._transport.auth_publickey(username, key))
      File "/usr/lib/python3.4/site-packages/paramiko/transport.py", line 1450, in auth_publickey
        return self.auth_handler.wait_for_response(my_event)
      File "/usr/lib/python3.4/site-packages/paramiko/auth_handler.py", line 226, in wait_for_response
        raise e
    
    
  3. tantorrrr commented on Apr 20, 2018

    @tantorrrr

    anyone here for help, I met this issue too

  4. alexanderhawl commented on May 29, 2018

    @alexanderhawl

    i also met this issue too, i donot know how to solve it

  5. eldridgea commented on Jun 22, 2018

    @eldridgea

    I am seeing the same issue when using the example file rforward.py. rforward.py works when authenticating with a password, and standard SSH works when authenticating with a private key.

    For reference here is the output in syslog on the SSH server:

    Jun 22 22:49:41 ubuntu-s-1vcpu-1gb-sfo2-01 sshd[9275]: Connection closed by authenticating user $USER $IP_ADDRESS 60836 [preauth]

  6. bitprophet commented on Jun 26, 2018

    @bitprophet
    Member

    Can y'all try differing Paramiko versions to see if this was introduced at a specific point in time? More details on your exact keys (eg number of bits, how they were generated, etc) might shed a clue as well - RSA in general clearly still works for most users so something more specific must be at work here.

  7. dpbus commented on Dec 21, 2018

    @dpbus

    Also ran into this issue and it seems to be related to the key format. From what I can tell, private keys in the RFC4716 format are not supported by paramiko, while PEM (and maybe other) formatted keys are. Or, perhaps the version of openssl on the box where you're running determines the support of different key formats.

    I seems on recent versions of MacOS, ssh-keygen defaults to RFC4716 format, so those keys I generate on my mac were not working for me. Keys that I've generated on a linux box (debian) or using the -m PEM flag on MacOS do seem to work though.

  8. kariya2 commented on Feb 7, 2019

    @kariya2

    Running into the same issue, any update?

  9. ffleandro commented on Mar 7, 2019

    @ffleandro

    I'm also seeing this issue using paramiko 2.4.2.
    Here is the /var/log/auth.log on the server side:

    Mar 7 08:36:22 serverhostname sshd[7021]: Connection closed by 177.206.230.70 port 60465 [preauth]

    I can log to the server passing the private key file using the ssh -i key

  10. ffleandro commented on Mar 7, 2019

    @ffleandro

    @dpbus How can I check if my private key is in PEM format or RFC4716?
    Can I convert the private key without modifying my public key?
    How can I convert it to paramiko expected format?

  11. ffleandro commented on Mar 7, 2019

    @ffleandro

    After reading some more, I found that a PEM key file starts with
    —–BEGIN RSA PRIVATE KEY—–

    And a RFC4716 starts with:
    —–BEGIN OPENSSH PRIVATE KEY—–

    My file is a PEM key file, so it is not the problem @dpbus mentioned.
    Any comments?

  12. eepstein commented on Apr 19, 2019

    @eepstein

    @ffleandro (or anyone else) any resolution on this?

  13. ffleandro commented on Apr 22, 2019

    @ffleandro

    @eepstein Yes I solved the following way. I don't remember the previous code but I think I was opening the key the wrong way or I was passing the password to the connect instead of passing when opening the key.

    key = paramiko.RSAKey.from_private_key_file('key/file/path', password='key_password')
    warnings.filterwarnings(action='ignore',module='.*
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host, username=user, port=port, password=password, look_for_keys=False, pkey=key)
    
  14. bitprophet commented on May 31, 2019

    @bitprophet
    Member

    This smells like another dupe of the handful of missing-OpenSSH-feature tickets out there (there's at least 3-4). Please keep an eye on the changelog over the next few weeks/months!

  15. jamesharris-garmin commented on Nov 19, 2019

    @jamesharris-garmin

    @bitprophet I don't think there is an existing ticket for this issue. (after doing some searching) should we re-open this ticket? or create a more formal request for this ticket with a simple use case?

    It seems like more people are running to this issue as openssh v8 is deployed more widely.

    Reference information is: https://coolaj86.com/articles/the-openssh-private-key-format/

  16. ploxiln commented on Nov 19, 2019

    @ploxiln
    Contributor

    for the new openssh private key format see #1343

  17. Chaz6 commented on Aug 3, 2022

    @Chaz6

    I have confirmed with exactly the same code, paramiko 2.8.1 works whereas any version from 2.9.0 onwards does not (up to 2.11.0).

    Sample code:-

    pkey = paramiko.RSAKey.from_private_key_file(LOGIN_KEY_FILE)
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=HOSTNAME,username=LOGIN_USERNAME,password=LOGIN_PASSWORD,sock=jumpbox_channel,pkey=pkey,look_for_keys=False)
    

    Edit: I fixed this as follows:-

    pkey = paramiko.RSAKey.from_private_key_file(LOGIN_KEY_FILE)
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=HOSTNAME,username=LOGIN_USERNAME,password=LOGIN_PASSWORD,sock=jumpbox_channel,pkey=pkey,look_for_keys=False,disabled_algorithms={'pubkeys': ['rsa-sha2-512', 'rsa-sha2-256']})
    
  18. andyhasit commented on Oct 1, 2022

    @andyhasit

    I am also getting this error when I connect to one server, but not another. Both servers use the same keys (hobby project). I can ssh into both. Paramiko works on one server but fails on the other, and the error message really makes it look like a local issue. I tried versions 2.4 - 2.11.

  19. bskinn commented on Oct 3, 2022

    @bskinn
    Contributor

    @andyhasit If you're seeing this same error, but in a fashion that's different from the manifestation OP was seeing and one that you're having trouble debugging, your best bet is probably to create a new issue and link back to this one.

    You might also get some help on Stack Overflow, not sure.

  20. zhenfzha commented on Nov 28, 2022

    @zhenfzha

    I have the same issue. It seems to be stuck here,
    [paramiko.transport] INFO Connected (version 2.0, client X)
    [paramiko.transport] INFO Authentication (publickey) failed.
    [paramiko.transport] INFO Authentication (keyboard-interactive) successful!
    I can provide the debug log

    图片

  21. bskinn commented on Nov 28, 2022

    @bskinn
    Contributor

    @zhenfzha As above, if you're seeing this same error, but in a fashion that's different from what the OP was seeing and one that you're having trouble debugging, your best bet is probably to create a new issue and link back to this one.

    You might also get some help on Stack Overflow, not sure.

  22. ronaldmeran commented on Apr 17, 2025

    @ronaldmeran

    I have confirmed with exactly the same code, paramiko 2.8.1 works whereas any version from 2.9.0 onwards does not (up to 2.11.0).

    Sample code:-

    pkey = paramiko.RSAKey.from_private_key_file(LOGIN_KEY_FILE)
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=HOSTNAME,username=LOGIN_USERNAME,password=LOGIN_PASSWORD,sock=jumpbox_channel,pkey=pkey,look_for_keys=False)
    

    Edit: I fixed this as follows:-

    pkey = paramiko.RSAKey.from_private_key_file(LOGIN_KEY_FILE)
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=HOSTNAME,username=LOGIN_USERNAME,password=LOGIN_PASSWORD,sock=jumpbox_channel,pkey=pkey,look_for_keys=False,disabled_algorithms={'pubkeys': ['rsa-sha2-512', 'rsa-sha2-256']})
    

    This fixed it for me, adding the disabled_algorithms parameter. It seems it's parsing the key to one of these algo that's why it keeps on failing to authenticate.

  23. manparmo commented on Jul 27, 2025

    @manparmo

    Same problem with some network gear, I did the following (based on previous answers but simplified)

    try:
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(gw['ip'], username=self.username, password=self.password,look_for_keys=False,disabled_algorithms={'pubkeys': ['rsa-sha2-512', 'rsa-sha2-256']})
    interact = SSHClientInteraction(ssh, timeout=30, display=False, buffer_size=60000)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions