Skip to content

Authenthication failed with key authentication in paramiko 2.9+ #2143

Open

Description

@mawilms

Hello everyone,

I've created a ssh key pair via ssh-keygen -f bla -C "" and I'm able to log into the customers sftp server via the command line.

Unfortunately it is not possible to use the same private key to log into the server via paramiko unless I use Paramiko 2.8.1. I've used 2.12.0 before. Interesting is that I was able to establish a ssh connection via paramiko 2.12.0 to a sftp server run via the SFTP Docker image by atmoz.

Could be related to 1135 and 1791

Tl;dr:

  • Command line ssh and sftp connection successful
  • SFTP connection via paramiko 2.12.0 to Atmoz SFTP Docker image
  • SFTP connection via paramiko 2.8.1 to customer server
  • SFTP connection via paramiko 2.12.0 to customer server

Activity

  1. nyoungstudios commented on Dec 9, 2022

    @nyoungstudios

    I was having this exact same problem, here is why it works in paramiko 2.8.1 but not paramiko 2.9.0. This is because your ssh key is a RSA key using the SHA1 signature. This is otherwise known as "ssh-rsa". Comparing the diff between those two tags in the repo (scroll down to the paramiko/transport.py file on line 180 and 181 - and similarly on line 191 and 192), you'll see that in version 2.9.0, "rsa-sha2-512" and "rsa-sha2-256" were added before "ssh-rsa".

    This means it will try to use one of these new algorithms first in the new version. A simple fix is to pass the algorithms that you do not want to use in the disabled_algorithms parameter. For example,

    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(
        hostname="", 
        username="", 
        pkey=pkey, 
        disabled_algorithms={
            "pubkeys": ["rsa-sha2-256", "rsa-sha2-512"]
        }
    )
  2. vmoravec commented on Dec 14, 2022

    @vmoravec

    Another option is to configure the transport for the server via e.g. transport.server_extensions = {'server-sig-algs': 'ssh-rsa'} . Worked for paramiko version 2.12.0

  3. avatarofhope2 commented on Jan 12, 2023

    @avatarofhope2

    I ran into this problem with 2.12.0

    Once I added disabled_algorithms={"pubkeys": ["rsa-sha2-256", "rsa-sha2-512"]}, it worked once again, but why are the algorithms a list if it will never get to the algorithm that actually works? I don't think I understand the root cause here. Is there something else going on here? is the issue here how the key was generated?

  4. upperdeck commented on Feb 27, 2023

    @upperdeck

    I am struggling with this same type ssh issue.. when i add the code disabled_algorithms={"pubkeys": ["rsa-sha2-256", "rsa-sha2-512"]} I then get

    Exception: (<class 'TypeError'>, TypeError("'NoneType' object does not support the context manager protocol"), <traceback object at 0x0315D9A8>)

    the key_path is pointing to a PEM file
    thoughts?

    All is working fine on this server using ppk file and filezilla.. and the code works fine on our original server, but the new one has a newer version of paramiko. So I added the disabled_algorithims code

    code is

    ssh.connect(hostname = 'xxx.xx.xxx.xxx',
    port=22,
    username="username",
    key_filename=key_path,
    password = pwd,
    disabled_algorithms={"pubkeys": ["rsa-sha2-256", "rsa-sha2-512"]})

  5. bskinn commented on Feb 28, 2023

    @bskinn
    Contributor

    Marking this as likely relevant to the key/auth overhaul of #387.

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