On Linux and Apple Mac OS X operating systems, the
~/.ssh/config file enables you to specify many SSH settings, including those that keep alive an SSH connection. To do this, follow these steps:
Use your preferred text editor to open the
~/.ssh/config file on your local computer. Note: If the
.ssh directory or the config file do not exist, create them.
Add the following lines to the config file. The Host value can be any name you want; it is simply a label for the other settings. The Hostname value is the remote host you want to access; replace example.com with your domain name. Replace username with your own Hosting account username:
With this configuration, the SSH client sends a packet to the server every 240 seconds (4 minutes) to keep the connection alive. If the client does not receive a response after two tries (as specified by the ServerAliveCountMax setting), it closes the connection.
For detailed information about all of the SSH configuration settings available, type
man ssh_config at the command line.
Save the changes to the config file.
Connect to your account using SSH. To do this, simply type ssh example where example represents the Host value you specified in step 2.
Monitor the connection. If it still drops, gradually decrease the
ServerAliveInterval setting in the config file until the connection is stable.
Check the following url for more details https://www.a2hosting.com/kb/getting-started-guide/accessing-your-account/keeping-ssh-connections-alive