How To set Auto Logout for Linux users

What is this auto logout?
Ans : Auto logout is a concept to force user to logout from the remote server. If the open session to remote server is idle for a given time. This is a security measure Linux administrators follow for terminating idel sessions to remote servers.
Why actually we require auto logout?
Ans : As a security measure, This is a good practice to set this, because its not a good idea/practice to keep open terminal idle for longer duriations.
How to accomplish this for a system wide setting?
Ans : This can be achieved by two ways.

1. Open /etc/profile and append TMOUT variable. See my below example

Export TMOUT=600 # 10 minutes in seconds
typeset -r TMOUT
This will set time-out to 600 sec(ie 10mins) and I have given typeset -r which read-only and will not allow users to change this. Save the file and exit.

 

2. By creating /etc/profile.d/sessiontimout.sh file then keeping above mention entries in it.
Export TMOUT=600 # 10 minutes in seconds
typeset -r TMOUT
Now save and exit the file

As this is a script we have to change the permissions too.
#chmod +x /etc/profile.d/sessiontimout.sh

How to accomplish this for individual users?

Ans : We can edit ~/.bashrc file as given below.

Open ~/.bashrc file for a given user and write below two line in to it.

TMOUT=600

export TMOUT

Save the file and source it as given below.

source ~/.bashrc

This change can be seen only for that user. Please share your thoughts on this, if you know better option to do it.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.
  • Arun

    this set up is for all the users, how to do it for a single user

    • http://www.linuxnix.com Surendra Anne

      Hi Arun,

      You can keep below lines in your ~/.bashrc file(For every user, they have their own .bashrc files).

      TMOUT=600
      export TMOUT

      Save the file and source it.

      source ~/.bashrc

      Hope this helps and I updated the post to include this as well.

      Thanks,
      Surendra.

  • Albin

    How to record  in /var/log/message if user session expires due to time out.

banner