If you are working with command line you may have come across frequent SSH Timeout issues after a few minutes of inactivity. This is very annoying because you need to open a new console and reconnect and perform any other steps you need before connecting.
Usually what happens is that your connection to the server is reset when your idle time exceeds that value the session times out.
Solution to SSH Timeout issues:
By sending a “null packet” between the client and the server at a specified interval that is smaller than the timeout value, we can avoid SSH timeout. It doesn’t matter if the packet is sent from the client or the server, as long as there is some communication going on between the two.
SSH Client Configuration (Linux):
If you are connecting from a Linux system, please follow the steps below to keep the SSH session alive.
Step 1: Log in as root
Step 2: Edit the file at /etc/ssh/ssh_config
Step 3: Add this line to the file: ServerAliveInterval 60
Step 4: Save the file
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set. This option applies to protocol version 2 only.
Putty Configuration (Windows)
If you are connecting from Putty, please follow the steps below to keep the SSH session alive.
Step 1: Open PuTTY
Step 2: Click on the Connection Category in the left menu
Step 3: Add seconds between keep alive, based on your sever. If not sure put 120.
Step 4: Check the box for Enable TCP keepalives (SO_KEEPALIVE option)
That’s it!!! You are done.