Skip to Content

2 Steps to increase Linux SSH connection Timeout

In this tutorial, we will learn how to increase SSH Connection timeout value in Linux.

What is the ssh connection timeout in Linux?

The ssh connection timeout is the time that a connection will remain open before it times out and closes. This timeout can be caused by a variety of factors, including network congestion, incorrect configuration settings, or an inactive session.

What are some causes of ssh connection timeout in Linux?

There are a few different reasons why your ssh connection might timeout. One common cause is if the server is configured to close idle connections after a certain amount of time. Another possibility is that there is network congestion or a problem with the network connection between your computer and the server.

2 Steps to increase SSH connection timeout in Linux

  1. Use ServerAliveInterval SSH option when connect to remote server
  2. Change the user timeout value through the TMOUT variable on the server


Use ServerAliveInterval SSH option when connect to remote server in Linux

ServerAliveInterval: this is the interval when the client sends the probe message to the server. The ServerAliveInterval option prevents our router from thinking the SSH connection is idle by sending packets over the network between our device and the destination server every n seconds. This is also referred to as “keep alive” traffic: sending traffic only to keep the connection alive.

There are two ways to use this option. We can add this option to the command line like this $ ssh -o ServerAliveInterval=20 ip or write this option to the configuration file like this.

touch ~/.ssh/config
cat << EOF >> ~/.ssh/config
host *
ServerAliveInterval 20

Change TMOUT on the server-side in Linux

Tmout is a bash variable to auto-logout Linux users when there isn’t any activity. By default it is very short. We can change it based on our requirements.

export TMOUT
echo $TMOUT

Now the current ssh connection timeout is 10 minutes (600 seconds). We can increase this value if needed. Check the detailed info about how to increase SSH timeout value in Linux here.



Saturday 22nd of June 2024

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.