In this article, we would see how to enable auto logout feature when BASH is left inactive for a certain time period.
It has happened to most of us, we were working on BASH. All of a sudden, some new task came up. We got busy and forgot to logout from BASH. In other words, we have left our session idle.
We take all the security measures, but when we leave our System idle – we are exposing our system to infinite risks. The situation may turn to worse if we leave superuser session idle. So, we need to make sure the user is protected against all potential threats.
Presence of mind is required, and if for some reason the user is distracted. Then, we need to safeguard his/her system in every possible way. Therefore, it is good to configure our system so that it logs out users if a period of inactivity is tracked by the system.
That is where TMOUT is really helpful.
With TMOUT we can choose the time our session can be left inactive. Beyond the prescribed time limit, it will automatically logout the user.
We can achieve this by editing ~/.bashrc configuration file. Append the file with the following line of code –
For instance, if we want the idle session to log out after 3 minutes. Then, convert 3 minutes to seconds. 1 minute is equal to 60 seconds. Therefore, 3 minutes will have 180 seconds. Hence, use the following instructions –
When there is no response from the user for 180 seconds then, the shell automatically logs out the user.
Alternately, we can also directly pass the code in the terminal itself. But, that is not advisable because we need to provide it every time a user logs in. Just issue the following in terminal –
Same as before, it will automatically log out the user after 60 seconds.
In conclusion, TMOUT is a very useful tool available for those who inadvertently leave their system logged in. A user would have to find the right balance. The timer shouldn’t set off too early or late. Otherwise, it would unnecessarily trouble the logged in user.