Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paramiko can't connect to ssh server

I want to send a command over ssh with python

from paramiko import SSHClient
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect("192.168.0.62",port="22", username="username", password="password")

And when i run it I get this

  File "prog.py", line 8, in <module>
    ssh.connect("192.168.0.62",port="22", username="username", password="password")
  File "/home/rick/.local/lib/python2.7/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/home/rick/.local/lib/python2.7/site-packages/paramiko/client.py", line 824, in missing_host_key
    "Server {!r} not found in known_hosts".format(hostname)
paramiko.ssh_exception.SSHException: Server '[192.168.0.62]:22' not found in known_hosts

What should i do


1 Answers

If it's private network try adding line ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) after creation of SSHClient.

AutoAddPolicy from Paramiko docs

like image 171
rok Avatar answered Sep 21 '25 11:09

rok