Bash: extend timeout for idle ssh sessions using TMOUT

The ClientAliveInterval and ClientAliveMaxCount settings in “/etc/sshd/sshd_config” work together to control the timeout value of an ssh session on the server side.  But under BASH, to keep idle client sessions from timing out, you also need to set the ‘TMOUT’ variable or you will see messages like below when disconnected.

timed out waiting for input: auto-logout

The TMOUT variable can be set at the system level or user profile level, and controls the number of seconds that an idle session will remain active before being dropped.  This environment variable is read-only, so we need to modify the value in the existing configs if it is already there.

# check if TMOUT is already defined at system level
cd /etc/profile.d
sudo grep -sr TMOUT -l

# if found, then modify value
sudo sed -i 's/TMOUT=.*/TMOUT=600/' $(sudo grep -sr ^TMOUT -l | head -n1)

# if not found, then create a script
sudo touch 99-TMOUT.sh && sudo chmod 754 99-TMOUT.sh
echo "export TMOUT=600" | sudo tee 99-TMOUT.sh

Although this could be exported from the “/etc/profile” file itself, it is better practice to customize inside the “/etc/profile.d” directory.

REFERENCES

tecmint.com, timeout on idle activity for BASH sessions

howtouserlinux.com, ssh timeout in linux

urcloud.com, increase ssh timeout

Senthilkumar Palani, auto logout inactive users

NOTES

Convert private key to putty ppk [1,2]

# install cli tools
sudo apt install putty putty-tools -y

# convert RSA private key to putty PPK format
puttygen private-pem -o private-pem.ppk -O private

ClientAliveInterval is the number of seconds between sending a null packet to the client, and ClientAliveMaxCount is how many client alive messages will be sent without response before the sshd daemon drop the session.

total timeout seconds = ClientAliveInterval * ClientAliveMaxCount