How to automatically logout user from the login shell after period of inactivity

I want to automatically logout user from the login shell after defined period of inactivity, but leave X Window Terminals untouched. This will allow me to enhance security a little bit, as I will not accidentally leave superuser session running for a long period of time.

The proper way to achieve this is to set TMOUT variable to the number of seconds to wait for an user input using global profile.

Do not worry as you can keep your application running (like top, mc or long running process) and it will be not terminated.

Execute following commands to define 120 seconds timeout.

$ cat << EOF | sudo tee /etc/profile.d/tmout.sh
# Execute only outside of X-terminal
[ -z "\$DISPLAY"  ] || return 0

export TMOUT=120
EOF
$ sudo chmod 644 /etc/profile.d/tmout.sh	

Changes will take place after user re-login. Bash will simply terminate after timeout.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu