Q: When I connect to one of my Linux servers via SSH, after about 10 minutes of inactivity my connection is closed. How do I stop this from happening.
A: You can configure your SSH client to send a small packet called no-op (no operation). The no-op is basically tells the other system “Nothing to do” but in communicating with the system tells SSH that your alive on the other side, thus not closing the TCP connection and logging you out.
To configure this ssh option for your current username only, add the following line to “/home/user/.ssh/config” or “~/.ssh/config” (the tilde “~” is just an alias for your home directory):
Host *
ServerAliveInterval 60
The “Host *” line basically tells the client to apply the settings to ANY host. Will the number after “ServerAliveInterval” is the amount of seconds to wait to send a no-op.
If you would like to apply this to one host only, you can. You can also adjust the interval seconds to meet your needs.
Host putorius.net
ServerAliveInterval 300
Now you have to read (or source) the file like so:
source ~/.ssh/config
That configured your client to send a no-op every 60 seconds. This will ONLY effect the one user with this in his/her home directory.
To apply this setting globally (or to ALL users) you can add (or change) the line in /etc/ssh/ssh_config:
ServerAliveInterval 60
NOTE: Make sure you add it to the SSH CLIENT configuration “ssh_config” and not the SSH SERVER configuration “sshd_config”.
Let me add, SSH sessions are usually logged out after a certain amount of time for security reasons. It is a best practice to close idle sessions to avoid unattended access to a system. Many companies have policies that govern system configurations. Circumventing these policies could be grounds for disciplinary actions.
Related Articles:
How to Save Per Host User Specific SSH Client Settings
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)