How to configure an equivalent of ssh StrictHostKeyChecking=no in Python Paramiko

Viewed 3705

I am using Paramiko for sshing from Python script. My ssh command is listed below:

ssh -A -o strictHostKeyChecking=no <hostname>

I need same Paramiko code for Python.

1 Answers

In Paramiko, an equivalent of OpenSSH StrictHostKeyChecking=no is the default behaviour of MissingHostKeyPolicy, which implements missing_host_key to simply do nothing.

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
client.connect(hostname, ...)

Though you should not do this (and neither StrictHostKeyChecking=no). You are losing a protection against Man-in-the-middle attacks this way. For correct solution, see Paramiko "Unknown Server".

Related