Skip to content

SSH Authentication fails with 2.9.2 #1984

Closed

Description

@tpcgold

This code snippet is working with 2.8.1 but not with 2.9.2:

import paramiko
import io

host = ''
port = ''
ssh_key = ''
username = ''
password = ''

transport = paramiko.Transport((host, int(port)))
rsa_key = paramiko.RSAKey.from_private_key(io.StringIO(ssh_key), password=password)
transport.connect(username=username, pkey=rsa_key)
sftp = paramiko.SFTPClient.from_transport(transport)
print(sftp.listdir())

Authentication Error is thrown by 2.9.2 downgrade solves the issue

Activity

  1. jun66j5 commented on Feb 9, 2022

    @jun66j5
    Contributor

    If the host is a legacy SSH server which doesn't support rsa-sha2-256/512 signatures, you need to use disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']} to fix it.

    See https://www.paramiko.org/changelog.html#2.9.0

    If the issue is not fixed even using disabled_algorithms, please share the trace back of the AuthenticationError.

  2. vitali-r commented on Feb 9, 2022

    @vitali-r

    I have the same issue. Downgrading to 2.8.1 helps. Downgrading to 2.9.0 does not help. Passing disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']} does not help

    Traceback (most recent call last):
      File "/home/project_folder/project/common/scp.py", line 105, in __enter__
        self._ssh.connect(**ssh_credentials)
      File "/home/project_folder/.venv/lib/python3.9/site-packages/paramiko/client.py", line 435, in connect
        self._auth(
      File "/project_folder/.venv/lib/python3.9/site-packages/paramiko/client.py", line 766, in _auth
        raise saved_exception
      File "/project_folder/.venv/lib/python3.9/site-packages/paramiko/client.py", line 742, in _auth
        self._transport.auth_publickey(username, key)
      File "/project_folder/.venv/lib/python3.9/site-packages/paramiko/transport.py", line 1634, in auth_publickey
        return self.auth_handler.wait_for_response(my_event)
      File "/project_folder/.venv/lib/python3.9/site-packages/paramiko/auth_handler.py", line 258, in wait_for_response
        raise e
    paramiko.ssh_exception.AuthenticationException: Authentication failed.
    
  3. jun66j5 commented on Feb 9, 2022

    @jun66j5
    Contributor

    I have the same issue. Downgrading to 2.8.1 helps. Downgrading to 2.9.0 does not help. Passing disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']} does not help

    • What SSH server and the version are you using?
    • Check log of your SSH server.
  4. vitali-r commented on Feb 9, 2022

    @vitali-r

    I don't know the version and am unable to check the logs as it is the remote client's server.
    I figured out that commenting out these both two lines works for me:

        # ~= PubKeyAcceptedAlgorithms
        _preferred_pubkeys = (
            "ssh-ed25519",
            "ecdsa-sha2-nistp256",
            "ecdsa-sha2-nistp384",
            "ecdsa-sha2-nistp521",
            # "rsa-sha2-512",
            # "rsa-sha2-256",
            "ssh-rsa",
            "ssh-dss",
        )
    
  5. vitali-r commented on Feb 9, 2022

    @vitali-r

    Looks like the issue is in filtering out keys. Investigating now.

  6. jun66j5 commented on Feb 9, 2022

    @jun66j5
    Contributor

    Ah, I noticed https://www.paramiko.org/changelog.html#2.9.0 has typo about disabled_algorithms....

    Please try to pass:

    disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']}
    

    instead of:

    disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']}
    
  7. vitali-r commented on Feb 9, 2022

    @vitali-r

    Yep it worked! Thank you!

  8. bitprophet commented on Feb 11, 2022

    @bitprophet
    Member

    Good spot @jun66j5 - it's arguably not a typo as both of those dict-keys are valid ("keys" means host keys, "pubkeys" means public key auth - this follows from older, regrettable IMO, naming conventions 😂 ) but I've just updated the changelog to be more explicit about the pubkey version of the config. (see c9a3409)

  9. marc-swingler commented on Feb 13, 2022

    @marc-swingler

    Thanks, disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']} worked for me as well, hitting an old MINA implementation. ('keys' did not work for me either)

  10. realcp1018 commented on Feb 16, 2022

    @realcp1018

    Hi @bitprophet, I got the same error and solved it by: client.connect("<hostname>", disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']})

    Then got error Unable to agree on a pubkey algorithm for signing a 'ssh-rsa' key! for other hosts. Can we have a general way for this situation?
    Ps: I have to downgrade to 2.7.2 to adapt all hosts o(╥﹏╥)o

  11. ghostbody commented on Feb 19, 2022

    @ghostbody

    disabled_algorithms is a very bad idea if you really need it for both version ...

  12. bitprophet commented on Feb 25, 2022

    @bitprophet
    Member

    Yea I'm not very happy with disabled_algorithms as-is, it was fine for the fix it came in with, but is proving unintuitive/complex at this point in time. There are a few other small backwards incompatible API changes in the pipeline that will likely accompany the drop of Python 2 support - I expect changing this would be included there.

  13. marc-swingler commented on Feb 25, 2022

    @marc-swingler

    @realcp1018

    Hi @bitprophet, I got the same error and solved it by: client.connect("<hostname>", disabled_algorithms={'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']})

    Then got error Unable to agree on a pubkey algorithm for signing a 'ssh-rsa' key! for other hosts. Can we have a general way for this situation? Ps: I have to downgrade to 2.7.2 to adapt all hosts o(╥﹏╥)o

    I solved that by associating hostnames to dictionaries of connection parameters similar to stanzas in an ~/.ssh/config file.

  14. justinpryzby commented on Aug 22, 2022

    @justinpryzby

    The changelog still says "Specifically, you need to specify disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']} in either SSHClient or Transport. See below for details on why."

    Using "keys" and not "pubkeys". So I've had to rediscover the fix (after having put upgrading paramiko on hold for a couple weeks).

  15. bskinn commented on Aug 23, 2022

    @bskinn
    Contributor

    The changelog still says "Specifically, you need to specify disabled_algorithms={'keys': ['rsa-sha2-256', 'rsa-sha2-512']} in either SSHClient or Transport. See below for details on why."

    Using "keys" and not "pubkeys". So I've had to rediscover the fix (after having put upgrading paramiko on hold for a couple weeks).

    @justinpryzby Since you've been elbows-deep in understanding this, could you create a PR on the CHANGELOG with suitable edits?

    In particular, are there some circumstances where you want to use keys and some where you want to use pubkeys? Or is it just a typo, and it should always be pubkeys?

  16. justinpryzby commented on Aug 23, 2022

    @justinpryzby

    I think I'm only ankles-deep -- I know that "pubkeys" is what works for our application, and for other people who had opened github issues.

    But @bitprophet suggests that both keys are valid, and presumably some people will need "keys" (perhaps in addition to "pubkeys").
    #1984 (comment)

  17. bskinn commented on Aug 23, 2022

    @bskinn
    Contributor

    How's this for improved language, @justinpryzby: #2104

  18. justinpryzby commented on Aug 23, 2022

    @justinpryzby
  19. bskinn commented on Aug 23, 2022

    @bskinn
    Contributor

    Good catches, all - thanks, @justinpryzby! See revised PR.

    And yea -- the 'add suggestion' feature works decently if everything that needs changing is on a single line, but it's pretty bad for suggestions on multiline chunks.

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