How to keep SSH connections alive
This article describes how to keep SSH connections alive. If you experience problems when using SSH, such as dropped or unresponsive connections, you may need to adjust some settings in your SSH client.
The information in this article assumes that you have already set up an SSH client and are able to connect to your account. For more information about how to do this, please see this article
Keeping SSH connections alive
Depending on your hardware and software configuration, you may experience SSH connectivity issues. For example, some types of firewalls may preemptively close connections after a certain amount of time has elapsed.
To work around these types of problems, you can adjust your SSH client's settings. Follow the appropriate procedure below for your own operating system.
Windows operating systems
Microsoft Windows operating systems use the PuTTY program to establish SSH connections. If you experience connectivity issues, you can adjust PuTTY's configuration to help keep connections alive. To do this, follow these steps:
- Start PuTTY.
- Load your connection session.
- In the Category pane, click Connection.
- Under Sending of null packets to keep session active, in the Seconds between keepalives, type 240.
With this configuration, PuTTY sends a packet to the server every 240 seconds (4 minutes) to keep the connection alive.
- In the Category pane, click Session.
- Connect to your account and monitor the connection. If it stil drops, gradually decrease the keepalive interval until the connection is stable.
Linux and Mac OS X operating systems
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.
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 A2 Hosting account username:
Host example Hostname example.com Port 7822 User username ServerAliveInterval 240 ServerAliveCountMax 2
- 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.