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?
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.