5

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.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
Sameesh
  • 181
  • 6
  • 17

1 Answers1

7

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".

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846