Posted by chantra on July 15th, 2013
It can be useful to have a bash session automatically closing after some time. One of the obvious reason you might want this to happen is to make sure that no console is left with root access unwillingly.
Bash comes ready for this and can be configured to automatically terminate after waiting for activity for a given time.
By default, bash will wait indefinitely for input. But, there is a way to tell bash, or more exactly the read builtin command to timeout after some time of inactivity. This has the effect, for an interactive shell, to terminate after waiting for that time.
TMOUT is the environment variable that define that timeout.
In order to have this applied to ALL users on your system, you can create a file called: /etc/profile.d/bash_autologout.sh and add the following to it:
The next time a user will log in, they will set and export TMOUT and their shell will terminate after 10 minutes of inactivity.