Skip to content Skip to sidebar Skip to footer

Paramiko Ssh Failing With "server '...' Not Found In Known_hosts" When Run On Web Server

I am trying to use Paramiko to make an SSH communication between 2 servers on a private network. The client server is a web server and the host server is going to be a 'worker' ser

Solution 1:

You can hard-code the host key in your Python code, using HostKeys.add:

import paramiko
from base64 import decodebytes

keydata = b"""AAAAB3NzaC1yc2EAAAABIwAAAQEA0hV..."""
key = paramiko.RSAKey(data=decodebytes(keydata))
 
client = paramiko.SSHClient()
client.get_host_keys().add('example.com', 'ssh-rsa', key)
client.connect(...)

Or, as you are connecting within a private network, you can give up on verifying host key altogether, using AutoAddPolicy:

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(...)

(This can be done only if you do not need the connection to be secure, like when connecting within a private network)

Post a Comment for "Paramiko Ssh Failing With "server '...' Not Found In Known_hosts" When Run On Web Server"