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?


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.

  • 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? – Rapti Jun 27 '16 at 19:46
  • See my updated answer – Lorenz Jun 27 '16 at 19:48
  • 1
    The options are called ServerAliveInterval and ServerAliveCountMax at least in my installation, but this works great. Thanks! – Rapti Jun 28 '16 at 9:13
  • @Rapti Both options exist. These are the clientside options, yours the server side ones. – Lorenz Jun 28 '16 at 10:50
  • But ssh gives me some error when trying to use the Client options. man also only knows about the Server ones. – Rapti Jun 28 '16 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.