How can you get the SSH return code using Paramiko?

A much easier example that doesn’t involve invoking the “lower level” channel class directly (i.e. – NOT using the client.get_transport().open_session() command):

import paramiko

client = paramiko.SSHClient()

stdin, stdout, stderr = client.exec_command("uptime")
print    # status is 0

stdin, stdout, stderr = client.exec_command("oauwhduawhd")
print    # status is 127

Leave a Comment