If you’ve ever used SSH (Secure Shell) to access a server or computer remotely, you may have encountered the SSH timeout issue. The SSH timeout is a common problem when an SSH connection is inactive for a specific time, causing the connection to be closed automatically. This can be frustrating, especially if you’re in the middle of a long-running task or transferring a large file. Fortunately, there are several ways to disable SSH timeout; we’ll cover them in this comprehensive guide.
What is SSH Timeout?
Before we dive into the methods of disabling SSH timeout, let’s first understand what SSH timeout is and why it occurs. SSH is a secure protocol used to connect to remote servers or computers. When you establish an SSH connection, your client (such as PuTTY or OpenSSH) sends packets to the server to keep the connection alive. If no packets are sent or received for a certain period, the server assumes that the connection is inactive and closes it automatically. This is known as SSH timeout.
By default, most SSH servers have a timeout period of 15 minutes, meaning that if there’s no activity on the connection for 15 minutes, the connection will be closed. While this is a security measure to prevent unauthorized access, it can be problematic if you work on a long-running task or transfer large files.
Note: Remember that SSH servers have this timeout for a reason. Disabling it might open an exploit for hackers, so be careful when changing this option.
Methods to Disable SSH Timeout
Method 1: Editing SSH Configuration File
One way to disable SSH timeout is by editing the SSH configuration file. The configuration file for OpenSSH is located at /etc/ssh/sshd_config
(on most Linux systems). You can edit this file using a text editor such as nano or vi. Before editing the file, it’s a good idea to make a backup copy in case something goes wrong.
- Open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
- Locate the following line:
#ClientAliveInterval 0
- Uncomment the line by removing the
#
character, and change the value to a larger number (in seconds) than the default 15 minutes. For example:
ClientAliveInterval 300
This will send a packet to the client every 5 minutes (300 seconds) to keep the connection alive.
- Save and close the file by pressing
Ctrl+X
, thenY
, andEnter
. - Restart the SSH service to apply the changes:
sudo service ssh restart
After following these steps, your SSH connection will no longer time out after 15 minutes of inactivity.
Method 2: Using SSH Keepalive
Another way to prevent SSH timeout is by using SSH keepalive. SSH keepalive is a feature that sends null packets to the server at a regular interval to keep the connection alive. This method is useful if you don’t have root access to the server and can’t edit the SSH configuration file.
- Open your SSH client (such as PuTTY) and go to the Session settings.
- Under the Connection category, check the box next to “Enable TCP keepalives” or “Enable SSH keepalives” (depending on your client).
- Set the “Seconds between keepalives” to a value larger than the default 15 minutes. For example, set it to 300 seconds to send a keepalive packet every 5 minutes.
- Save the settings and connect to your server as usual.
After following these steps, your SSH connection should no longer time out due to inactivity.
Conclusion
SSH timeout can be frustrating, but fortunately, several ways exist to disable it. You can edit the SSH configuration file to increase the timeout period or use SSH keepalive to send regular packets to the server. Both methods effectively prevent SSH timeout, and the choice between them depends on your specific situation.
It’s worth noting that disabling SSH timeout can have security implications, as it increases the risk of unauthorized access if a connection is left open for a long time. Therefore, it’s essential to balance convenience with security when making these changes.
In summary, SSH timeout is a common problem that can be easily fixed by editing the SSH configuration file or using SSH keepalive. By following the steps outlined in this guide, you can prevent SSH timeout and continue working on your remote server or computer without interruption.
Learn more
Here are some additional resources that you may find helpful:
📕 Related articles about Linux
- How to change SSH key file format
- How to Disable Password Authentication in SSH
- How to Remove an Existing User in Linux
- How to mount disk partition using UUID in Linux
- How to Deny Specific User to SSH: A Comprehensive Guide
- How to Create RAR File Archive in Linux