SSH: Set timeout for broken pipe

5,377

The option ClientAliveInterval does exactly what you want, it basically sends pings in the specified interval (in seconds) and kills the connection if it doesn't receive an answer.

To control how fast it kills the connection, you can use ClientAliveCountMax, which is the maximum number of pings to send without receiving a response before considering the connection dead.

Share:
5,377

Related videos on Youtube

Rapti
Author by

Rapti

SOreadytohelp

Updated on September 18, 2022

Comments

  • Rapti
    Rapti over 1 year

    ssh has the paramater -o ConnectTimeout=10 to set the timeout in seconds when establishing the connection, but once the connection has been established, the parameter has no more effect. When an already established connection dies, ssh takes an incredible amount of time before telling me Broken Pipe. This is good in many cases as I can continue work after having network issues, but there are scenarios in which I want to use just a small timeout, maybe 10 to 20 seconds, for example when using tools like sshuttle. How can I do this?

  • Rapti
    Rapti almost 8 years
    So if it sends a ping every 10 seconds and doesn't receive an answer, will ssh exit 10 seconds after unplugging the network cable etc?
  • Lorenz
    Lorenz almost 8 years
    See my updated answer
  • Rapti
    Rapti almost 8 years
    The options are called ServerAliveInterval and ServerAliveCountMax at least in my installation, but this works great. Thanks!
  • Lorenz
    Lorenz almost 8 years
    @Rapti Both options exist. These are the clientside options, yours the server side ones.
  • Rapti
    Rapti almost 8 years
    But ssh gives me some error when trying to use the Client options. man also only knows about the Server ones.