Fix Linux SSH Timeout Quick Guide

Updated: Sep 5

A connection timeout indicates that the client attempted to establish a network socket to the SSH server, but the server failed to respond within the timeout period.


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





Steps to increase SSH connection timeout

  1. Create a user ssh configuration file if it doesn't exist on the client

  2. Add two lines to file ~/.ssh/config on the client

  3. Change the user timeout value through the TMOUT variable on the server

  4. Check TMOUT value on the server

Create a user ssh configuration file on the client-side

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.


we can use this way $ ssh -o ServerAliveInterval=n <user>@<ip> or write this option to the file.


We need to run the following command for this.


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




Change TMOUT on the server-side

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

TMOUT=600
export TMOUT
echo $TMOUT

Now the current ssh connection timeout is 10 minutes (600 seconds). We can increase this value if needed.


We can check the detailed info about how to increase SSH timeout value in Linux here.



Related:

Which SSH Key Is More Secure in Linux?

Filtering SSH Packets with Tcpdump

Setup SSH Keys to Login Linux Without Password

171 views
屏幕快照 2021-08-08 下午5.16.32.png