Auto Logout in Linux Shell Using TMOUT Shell Variable
TMOUT is a Linux-Unix shell variable that provides the user security for their login session in the system. It provides the “Auto Logout Functionality” for the login shell in case of no activity for a specified time.
Generally when the user leaves the Linux system idle (situation when a user doesn’t perform any administrative task by running a command or using GUI ( Graphical User Interface )) after the login as a root privilege, that time if anyone got physical access to the system via malicious attack that he has the full power as you and can execute any script that causes you a great loss.
So, It is a good idea to have the feature like auto-logout after a definite idle time.
All process is given the following stepwise and to follow the process run the following commands.
Step 1: Enable this globally (system-wide for all users), set the TMOUT variable in the /etc/profile shell initialization file.
$ sudo nano /etc/profile
Step 2: insert the given line
Note: Here 300 representing 300 seconds or 5 minutes.
Step 3: save and exit
Press Ctrl+x followed by "Y"
From now the user will automatically log out from the login session if there is no activity for a specific time (here that time is 5 minutes (300 seconds)).