Paramiko SSH failing with "Server '...' not found in known_hosts" when run on web server Paramiko SSH failing with "Server '...' not found in known_hosts" when run on web server apache apache

Paramiko SSH failing with "Server '...' not found in known_hosts" when run on web server


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

import paramikofrom base64 import decodebyteskeydata = 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)