Skip to content

Server <server name> not found in known_hosts #529

Closed

Description

@j9ac9k

I am trying to connect my ipython kernel to an existing kernel running on another machine through ssh. I was having trouble there and opened up an issue there that can be found here:

ipython/ipython#8439

With some guidance, it appears the issue is with paramiko.

For reference, I am running this on Windows 8.1 x64, I'm using git-bash for my command line work. I have python 3.4.3 installed and paramiko 1.15.2.

ogi@OGI-DESKTOP ~/Downloads
$ ssh ogi@hwvmsrv
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-37-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Sun May 17 17:06:06 PDT 2015

  System load:  0.0                Processes:           106
  Usage of /:   31.6% of 17.58GB   Users logged in:     1
  Memory usage: 5%                 IP address for eth0: 192.168.1.130
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

0 packages can be updated.
0 updates are security updates.

Last login: Sun May 17 17:06:07 2015 from 192.168.1.120
ogi@hwvmsrv:~$ exit
logout
Connection to hwvmsrv closed.

ogi@OGI-DESKTOP ~/Downloads
$ ipython
Python 3.4.3 |Continuum Analytics, Inc.| (default, Mar  6 2015, 12:06:10) [MSC v
.1600 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import paramiko

In [2]: client = paramiko.SSHClient()

In [3]: client.load_system_host_keys()

In [4]: server = 'hwvmsrv'

In [5]: username = 'ogi'

In [6]: port = 22

In [7]: keyfile = "C:\\Users\\ogi\\.ssh\\id_rsa"

In [8]: client.connect(server, port, username=username, key_filename=keyfile, lo
ok_for_keys=True)
---------------------------------------------------------------------------
SSHException                              Traceback (most recent call last)
<ipython-input-8-68c07a1ff1cf> in <module>()
----> 1 client.connect(server, port, username=username, key_filename=keyfile, lo
ok_for_keys=True)

c:\Users\ogi\Miniconda3\lib\site-packages\paramiko\client.py in connect(self, ho
stname, port, username, password, pkey, key_filename, timeout, allow_agent, look
_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_
timeout)
    286                 # will raise exception if the key is rejected; let that
fall out
    287                 self._policy.missing_host_key(self, server_hostkey_name,

--> 288                                               server_key)
    289                 # if the callback returns, assume the key is ok
    290                 our_server_key = server_key

c:\Users\ogi\Miniconda3\lib\site-packages\paramiko\client.py in missing_host_key
(self, client, hostname, key)
    568         client._log(DEBUG, 'Rejecting %s host key for %s: %s' %
    569                     (key.get_name(), hostname, hexlify(key.get_fingerpri
nt())))
--> 570         raise SSHException('Server %r not found in known_hosts' % hostna
me)
    571
    572

SSHException: Server 'hwvmsrv' not found in known_hosts

first line of known_hosts file (in same directory as id_rsa file)

hwvmsrv,192.168.1.130 ecdsa-sha2-nistp256 <key>

Any suggestions would be greatly appreciated.

Activity

  1. bitprophet commented on May 21, 2015

    @bitprophet
    Member

    Pretty sure this is a dupe of one of these tickets here: known_hosts - couple potential causes, if possible you should look into those scenarios and see which applies in your situation. Please follow whichever ticket seems to match best, or comment back here if you can provide confirmation that none of them apply :) Thanks!

  2. j9ac9k commented on May 22, 2015

    @j9ac9k
    Author

    I did manage to get a connection when I enabled an AutoAddPolicy() for the connection. If there is another means of troubleshooting, please advise.

    However going through the list of issues and the pull requests

    So #490 isn't relative to me:

    In [57]: hostkeys = paramiko.HostKeys()
    
    In [58]: hostkeys.load('C:\\Users\\ogi\\.ssh\\known_hosts')
    
    In [59]: 
    

    #437 deals with poor performance with loading known_hosts file which isn't relevant to me

    I'm not sure how to address #435.

    #138 deals with multiple keys for one server, I don't think it's an applicable situation, but it could be mistaken. I'm not sure how to implement the workaround that @gfxmonk implemented.

    I implemented #401 but I still got the same error.

  3. bitprophet commented on May 23, 2015

    @bitprophet
    Member

    OK, I didn't look closely enough at your output - the key type ecdsa-sha2-nistp256 made me realize it's actually probably #243 or #473 (both of which I just added to the known_hosts label, that feels like an oversight).

  4. drno-reg commented on Apr 4, 2017

    @drno-reg

    Hello,

    May be connect to server by SSH without using key_filename?

    for example

    import paramiko
    
    ssh = paramiko.SSHClient()
    HOSTNAME="192.168.0.27"
    USERNAME="user1"
    PASSWORD="pwd"
    PORT=22
    ssh.connect(HOSTNAME, PORT, username=USERNAME, password=PASSWORD)
    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("ps ax | grep 'user1'")
    

    p.s.
    now tried this code I got errors

    C:\Python36\python.exe C:/Server/repositories/templates/Test/SSH.py
    Traceback (most recent call last):
      File "C:/Server/repositories/templates/Test/SSH.py", line 37, in <module>
        ssh.connect(HOSTNAME, username=USERNAME, password=PASSWORD)
      File "C:\Python36\lib\site-packages\paramiko\client.py", line 362, in connect
        server_key)
      File "C:\Python36\lib\site-packages\paramiko\client.py", line 673, in missing_host_key
        raise SSHException('Server %r not found in known_hosts' % hostname)
    paramiko.ssh_exception.SSHException: Server '192.168.0.27' not found in known_hosts
    
  5. emilianobaum commented on Apr 9, 2020

    @emilianobaum

    this work from me:
    s.set_missing_host_key_policy(AutoAddPolicy())

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