TMOUT – Auto Logout Linux Shell When There Isn’t Any Activity

[‘

n

How often do you leave a Linux system idle after login; a situation which can be referred to as an ‘idle session’, where you are not attending to the system by running commands or any administration tasks.

n

However, this normally presents a great security risk, especially when your logged on as the superuser or with an account that can gain root privileges and in the event that someone with malicious intend gains physical access to your system, he or she can executes some destructive commands or do what ever they want to achieve on it, in the shortest time possibles.

n

Read Also: How to Monitor Linux Commands Executed by System Users in Real-time

n

Therefore, it is practically a good idea to always configure your system to automatically logout users in case of an idle session.

n

To enable automatic user logout, we will be using the TMOUT shell variable, which terminates a user’s login shell in case there is no activity for a given number of seconds that you can specify.

n

To enable this globally (system-wide for all users), set the above variable in the /etc/profile shell initialization file.

n

# vi /etc/profilern

n

Add the following line.

n

TMOUT=120rn

n

Save and close the file. From now on, a user will be logged out after 120 seconds (2 minutes), if he or she is not attending to the system.

n

Note that users can configure this in their own shell initialization file ~/.profile. This means that once that particular user has no activity on the system for the specified second, the shell automatically terminates, thus logging out that user.

n

Following are some useful security articles, go through it.

n

    n

  1. How to Monitor User Activity with psacct or acct Tools
  2. n

  3. How to Configure PAM to Audit Logging Shell User Activity
  4. n

  5. How to Block or Disable Normal User Logins in Linux
  6. n

  7. The Mega Guide To Harden and Secure CentOS 7 – Part 1
  8. n

  9. The Mega Guide To Harden and Secure CentOS 7 – Part 2
  10. n

n

That’s it! To share any thoughts or ask questions regarding this topic, use the feedback section below.

n

‘]