Linux – How to configure SSH client timeout after network failure

linuxsshtcp

Let's say I connect from a client to a server via SSH, and in the middle of the session I pull the server's network cable. On the client, the ssh connection stays alive for around 15 minutes before failing with a "Broken pipe" message. How can I adjust this timeout? In my case, I need to decrease it so that SSH fails early when there is a network issue.

I found a lot of information on how to avoid disconnections on idle sessions, or have longer connection setup timeouts, but not on the timeout of the established SSH connection itself. I also know there are such timeouts at the TCP level, but I suspect SSH sets up the socket with different values, as TCP timouts are normally around one minute, not the 15 minutes I am observing with SSH.

Client and server are both Ubuntu 14.04 server edition.

Best Answer

You can set the ServerAliveInterval and ServerAliveCountMax settings on the client. The maximum time before the client will disconnect is approximately the product of those two.