Skip to content

Problems with using ECDSA known_hosts keys when negotiation also accepts RSA or DSS keys #243

Open

Description

@airdrik

Ubuntu 12.04, paramiko 1.12
I'm trying to connect to a certain host whose only key in the known_hosts file is an ECDSA key, and paramiko is failing saying "server 'other-server' not found in known_hosts"

Investigating into the issue, I added a line to transport.py at line 1792 to print out agreed_keys, and it lists ('ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256').

I tried changing client.py and transport.py to pass in the host keys listed in known_hosts for the given host into the Transport and reduce the set of agreed keys to those listed in known_hosts, but I ran into an SSHException: Invalid key in Transport.start_client.

Activity

  1. adamgreig commented on Mar 21, 2014

    @adamgreig

    I'm also suffering from this issue -- since Ubuntu generates and uses ECDSA by default, my known_hosts generally only has ECDSA keys for Ubuntu servers, and so when Paramiko gets RSA keys from the server, it can't find them in known_hosts and bails.

    For reference, to fetch the remote's RSA key and add it to your known_hosts, you can...

    local$ ssh remote rsa-keyscan -t rsa remote >> ~/.ssh/known_hosts
    local$ ssh-keygen -H
    
  2. bitprophet commented on Mar 22, 2014

    @bitprophet
    Member

    This might be fixed by #218, currently too tired to tell offhand XD but want the link to be created so I or someone else checks...

  3. nikicat commented on Aug 29, 2014

    @nikicat

    @bitprophet as I can see #218 doesn't help

  4. bitprophet commented on Sep 3, 2014

    @bitprophet
    Member

    OK, thanks @nikicat.

    Also seeing reports similar to this in #350 which I'm merging into this one. Copying labels + adding high priority since this feels like a widespread problem :(

  5. added this to the 1.15 milestone on Sep 5, 2014
  6. changed the title [-]Problems with using ECDSA keys when negotiation also accepts RSA or DSS keys[/-] [+]Problems with using ECDSA known_hosts keys when negotiation also accepts RSA or DSS keys[/+] on Sep 6, 2014
  7. bitprophet commented on Sep 9, 2014

    @bitprophet
    Member

    I'm able to recreate this with an Ubuntu 13.10 VM known locally as ubuntu by doing the following:

    • Use regular ssh to connect; this adds (via 'ask' method) the RSA key to my personal known_hosts by default.
    • Use ssh-keyscan -t ecdsa localhost (NOTE: note rsa-keyscan as mentioned in Host Key Type Selection Should Match OpenSSH's #350. Assuming that was a typo?) on the VM to obtain its ECDSA key; copy that by hand into known_hosts on localhost.
    • Use Fabric as the driver, via fab -r -H ubuntu -- whoami (-r turns off an implicit Fabric-level triggering of Paramiko's auto-add-keys policy) for a simple sanity connection test.
    • With both keys enabled, it works fine.
    • With the RSA key commented out, it complains about not finding the host in known_hosts, as reported.

    Confirmed that the bug exists all the way from Paramiko 1.12 (first ECDSA release) through latest pre-1.15 master.

    Now looking through the code but the issue outlined in #350 sounds like the culprit - Transport is just too naive about deciding which key to seek out. (This is probably Yet Another Example of #387.)

  8. bitprophet commented on Sep 10, 2014

    @bitprophet
    Member

    Tried writing a test for this but once I got things working 'correctly' (vs having more fun #387 related key errors) the test actually passes without changes, meaning I probably need to do more work to ensure the test triggers the same code path having problems here (re: known_hosts).

    This is holding up release of 1.15 and also feels like the right fix may be tied up with the bigger changes needed for #387, so I am punting for now :(

  9. removed this from the 1.15 milestone on Sep 10, 2014
  10. pierreozoux commented on Mar 6, 2015

    @pierreozoux

    I'm hitting similar issue 👍

  11. kawing-chiu commented on Mar 9, 2015

    @kawing-chiu

    Similar issue here. client.load_system_host_keys() loads nothing from ~/.ssh/known_hosts. paramiko 1.15.2 on arch linux platfrom. Some entries in ~/.ssh/known_hosts:

    *.*.com,*.*.4.19 ssh-rsa AAAA...
    *.*.144.180 ecdsa-sha2-nistp256 AAAA...
    
  12. bitshark commented on Mar 26, 2015

    @bitshark

    FYI: For me, issue was a problem on Ubuntu 14 LTS apt-get package of paramiko ... But by simply by patching the one line in transport.py (as mentioned in another related isue to this one) to change the order of the keys... Then it works fine

  13. goshlanguage commented on Apr 2, 2015

    @goshlanguage

    I'm having this issue tried to connect to a Centos 7 vm to a keyed user.

  14. bitprophet commented on May 23, 2015

    @bitprophet
    Member

    #473 seems possibly related to this

  15. alanbchristie commented on Feb 25, 2019

    @alanbchristie

    We had this problem with version 2.1.1 of paramiko (installed by a 3rd-party library) and, searching for a solution, we stumbled on this issue.

    Not sure what to do, we upgraded to the latest version (pip install paramiko==2.4.2) and the problem appears to have been resolved. The cause of the fault may be very different but moving to the latest release fixed it for us.

  16. ploxiln commented on Feb 25, 2019

    @ploxiln
    Contributor

    This fix landed in 2.1.3: #910

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