Skip to content

paramiko does not automatically add unknown hosts #11

Open
@onyxfish

Description

@onyxfish
Owner
Connecting to SSH session on remote port 2222
Traceback (most recent call last):
  File "/usr/local/share/python/relay", line 9, in <module>
    load_entry_point('relay==0.0.8', 'console_scripts', 'relay')()
  File "/usr/local/lib/python2.7/site-packages/relay.py", line 187, in _main
    func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/relay.py", line 281, in ssh
    key_filename=env['pair_private_key']
  File "/usr/local/lib/python2.7/site-packages/paramiko/client.py", line 321, in connect
    self._policy.missing_host_key(self, server_hostkey_name, server_key)
  File "/usr/local/lib/python2.7/site-packages/paramiko/client.py", line 85, in missing_host_key
    raise SSHException('Server %r not found in known_hosts' % hostname)
paramiko.SSHException: Server '[54.244.243.254]:2222' not found in known_hosts

Activity

jmsalomr

jmsalomr commented on Oct 17, 2013

@jmsalomr

Hi,

I have the same problem. Is this a bug or I'm doing something wrong. I'm using paramiko in Python 2.7 32 bits over Windows 7.

jmsalomr

jmsalomr commented on Oct 17, 2013

@jmsalomr

Sorry, solved.

You have to use:

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) before

ghost

ghost commented on May 31, 2014

@ghost

You need add: ssh.load_system_host_keys() ..before ssh.connect

anirudt

anirudt commented on Dec 25, 2015

@anirudt

+1 @jmsalomr , that worked. Thanks.

anunayamar

anunayamar commented on Feb 10, 2016

@anunayamar

@jmsalomr you saved my time. Thanks!!

zlshi

zlshi commented on Aug 23, 2016

@zlshi

+1 @jmsalomr , that worked. Thanks.

tao12345666333

tao12345666333 commented on Oct 31, 2016

@tao12345666333

@jmsalomr Thanks.

AlexandreLicinio

AlexandreLicinio commented on Sep 11, 2017

@AlexandreLicinio

@jmsalomr thanks :) 👍

zed

zed commented on Feb 2, 2018

@zed

To modify ~/.ssh/known_hosts file (to save the keys permanently) in addition to AutoAddPolicy(), use client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')). Note: AutoAddPolicy() opens you to the MITM attack. See Paramiko: Add host_key to known_hosts permanently.

added a commit that references this issue on Dec 27, 2018
usama767

usama767 commented on Aug 13, 2020

@usama767
import paramiko as paramiko
from paramiko import AutoAddPolicy

ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(AutoAddPolicy())
ssh.connect('52.160.xx.xx', port=22, username='frt-user', password='xxxxxx',sock=None)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls')

i get this error
TypeError: 'NoneType' object is not callable

what is the step i am missing or doing wrong? @jmsalomr

akliorin

akliorin commented on Dec 4, 2020

@akliorin

@usama767

I ran into both of the issues in this thread.
First, adding the autopolicy does work most of the time.

To fix the NoneType error, I went to //.ssh and deleted everything. Started working.

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zed@onyxfish@tao12345666333@jmsalomr@anirudt

        Issue actions

          paramiko does not automatically add unknown hosts · Issue #11 · onyxfish/relay