Search code examples
pythonparamiko

Paramiko: Whats the difference between various timeouts?


We have multiple timeouts in the Paramiko library, which seems confusing on which to set when. The doc tried to describe them, but I don't understand their use cases. Like, when should I use one over the other?

connect method:

  1. timeout: an optional timeout (in seconds) for the TCP connect
  2. banner_timeout: an optional timeout (in seconds) to wait for the SSH banner to be presented.
  3. auth_timeout: an optional timeout (in seconds) to wait for an authentication response.

exec_command method:

  1. timeout: set command’s channel timeout. See Channel.settimeout

Solution

  • SSHClient.connect method:

    • timeout – TCP connection opening timeout (but maybe also for some other socket operations). But also timeout for SSH negotiation. Default is no timeout.
    • banner_timeout – After TCP connection is opened, how long to wait for the server to send anything (that is SSH banner). Default is 15 seconds.
    • auth_timeout – How long to wait for an authentication response (that's imo self-explanatory). Default is 30 seconds.

    SSHClient.exec_command method:

    • timeout – How long to wait for "exec" channel to open. And subsequently timeout for each output reading. Default is no timeout.