Should you’ve ever suffered from SSH automatic disconnection when you establish an SSH session to a server, this is due to a lack of activity between the server and the client. In most cases, the firewall that sits between them cuts the connection.
You can however force either the SSH client or the server to keep the session alive in these cases by sending KeepAlive packets to the other end.
On the client side you have to set the
variable in the /etc/ssh/ssh_config file where N is the number of seconds between each KeepAlive packet (120 should do).
Whether we want to have this behaviour on all the SSH connections to a specific server we better configure the server to keep the sessions open saving us to tweak each client’s configuration. Do this by adding:
in the /etc/ssh/sshd_config file.