relay
relay copied to clipboard
paramiko does not automatically add unknown hosts
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
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.
Sorry, solved.
You have to use:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) before
You need add: ssh.load_system_host_keys() ..before ssh.connect
+1 @jmsalomr , that worked. Thanks.
@jmsalomr you saved my time. Thanks!!
+1 @jmsalomr , that worked. Thanks.
@jmsalomr Thanks.
@jmsalomr thanks :) :+1:
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.
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
@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 /