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

h‮ww//:sptt‬w.lautturi.com
Linux / UNIX Automatically Logout BASH / TCSH / SSH Users After a Period of Inactivity

There are several ways to automatically log out users from a BASH, TCSH, or SSH session after a period of inactivity on a Linux or Unix system. Here are three possible approaches:

  1. Use the TMOUT variable:

You can set the TMOUT variable in the /etc/bashrc or /etc/bash.bashrc file to automatically log out inactive users after a specified number of seconds. For example:

TMOUT=1800

This will log out users who have not entered a command in the current BASH session for 1800 seconds (30 minutes). You can set the value of TMOUT to any number of seconds that you want.

  1. Use the autologout command:

The autologout command is a utility that is designed specifically to log out inactive users from a terminal session. It can be installed on most Linux and Unix systems through the package manager.

To use autologout, you need to specify the number of minutes of inactivity after which you want to log out the user. For example:

autologout 30

This will log out users who have not entered a command in the current terminal session for 30 minutes.

  1. Use the IdleLogout directive in sshd_config:

If you want to log out inactive SSH users, you can use the IdleLogout directive in the /etc/ssh/sshd_config file. This directive specifies the number of minutes of inactivity after which the user's session will be terminated.

For example:

IdleLogout 30

This will log out users who have not entered a command in their SSH session for 30 minutes.

Note: These approaches will only work if the user is actively using the terminal or SSH session. If the user is running a background process or is connected through screen or tmux, their session will not be terminated.

Created Time:2017-10-29 22:08:55  Author:lautturi