6

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
  • 188,800
  • 56
  • 490
  • 992
Sameesh
  • 315
  • 8
  • 18

1 Answers1

8

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
  • 188,800
  • 56
  • 490
  • 992
  • Excellent answer explaining that it shouldn't be done while still trusting the reader's judgement with exactly how to do it anyway. Thanks! – BytePorter Apr 03 '23 at 19:56