SSH Timeouts
- Some users might experience a timeout/disconnect after being logged into a system using ssh for some period of time of non-direct activity. For example, you might be logged into one of our Linux systems via ssh, and you might start up a process that is expected to take a long time to run. However, with no keyboard activity for a while while your process is running, ssh may time out and disconnect your session.
- Sometimes, firewalls (and other network characteristics) in-between your client and a server may affect ssh connection times. In other instances, there are settings you can make with your ssh client that might help prevent timeouts.
- So, settings to prevent ssh timeouts should be set at the client end, meaning, the system you're using to connect to a remote system.
- Due to the various ssh client programs people use to connect to servers, their configuration processes differ, so we cannot tell you how to set up your specific ssh client program. But, we can provide you some info if you run an OpenSSH client, just like our own CS Linux clients use...
Configure an OpenSSH Client To Prevent SSH Timeouts
- If you use OpenSSH to connect to a remote Linux system, on the system you're coming from, you could consider adding lines similar to the following three lines to your ~/.ssh/config file to help prevent SSH timeouts:
- Host *
- ServerAliveInterval 20
- ServerAliveCountMax 5
- In this example, for all hosts you connect to, if the client (your system) has not received anything for 20 seconds, your client will send an "invisible packet" to keep the connection alive. If your client sends 5 keepalive packets in a row without acknowledgement from the server, your client will close the connection.
- But, don't make your numbers too large or too small due to the way firewalls and the network handle the traffic. The above is just an example. You'd have to fine tune your configuration for your network environment.
- Please see your OpenSSH client's ssh_config(5) man page for additional options and more in-depth info about the above config lines.
- NOTE: if you add lines like the above to your ssh config file, due to the Host * line, these lines would apply to every system you connect to from your OpenSSH client. You'd have to use a more specific Host line in order to single out just the CS Linux systems.
Using tmux Or screen As An Alternative
- One thing many people do for long-running programs is to run them inside a tmux or screen session. That allows the programs to continue even if the SSH session is disconnected.
- If you do this, make sure you do come back to check on your programs! Sometimes, people forget about their runningprograms and leave them, unnecessarily using up computing resources that should be available for other people using our services.
- You can learn more about tmux here: https://tmux.github.io/