Linux / UNIX Automatically Logout BASH / TCSH / SSH Users After a Period of Inactivity

On Linux/UNIX systems, you can configure the shell or SSH server to automatically log out users after a period of inactivity using the TMOUT environment variable.

To automatically log out users after a period of inactivity, you can set the TMOUT variable in the user’s shell configuration file. For example, to set the timeout to 30 minutes (1800 seconds), you can add the following line to the user’s ~/.bashrc or ~/.bash_profile file:

TMOUT=1800

For users who use the TCSH shell, you can add the following line to the ~/.tcshrc file:

set autologout=30

The TMOUT variable specifies the number of seconds of inactivity after which the shell will automatically log out the user. The set autologout command in TCSH specifies the number of minutes of inactivity.

For SSH users, you can set the ClientAliveInterval and ClientAliveCountMax options in the /etc/ssh/sshd_config file to automatically log out users after a period of inactivity. For example, to set the timeout to 30 minutes (1800 seconds) and a maximum of 3 client alive messages, you can add the following lines to the file:

ClientAliveInterval 1800
ClientAliveCountMax 3

These options will send a “keep-alive” message to the client every 1800 seconds and terminate the connection after three unanswered messages, effectively logging out the user after 30 minutes of inactivity.

Leave a Comment