Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paramiko does not automatically add unknown hosts #11

Open
onyxfish opened this issue Mar 14, 2013 · 11 comments
Open

paramiko does not automatically add unknown hosts #11

onyxfish opened this issue Mar 14, 2013 · 11 comments

Comments

@onyxfish
Copy link
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
@jmsalomr
Copy link

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
Copy link

Sorry, solved.

You have to use:

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) before

@ghost
Copy link

ghost commented May 31, 2014

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

@anirudt
Copy link

anirudt commented Dec 25, 2015

+1 @jmsalomr , that worked. Thanks.

@anunayamar
Copy link

@jmsalomr you saved my time. Thanks!!

@zlshi
Copy link

zlshi commented Aug 23, 2016

+1 @jmsalomr , that worked. Thanks.

@tao12345666333
Copy link

@jmsalomr Thanks.

@AlexandreLicinio
Copy link

@jmsalomr thanks :) 👍

@zed
Copy link

zed commented Feb 2, 2018

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.

@usama767
Copy link

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
Copy link

akliorin commented Dec 4, 2020

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants