≡ Menu

Linux: TMOUT To Automatically Log Users Out

How do I auto Logout my shell user in Linux after certain minutes of inactivity?

Linux bash shell allows you to define the TMOUT environment variable. Set TMOUT to automatically log users out after a period of inactivity. The value is defined in seconds. For example,

export TMOUT=120

The above command will implement a 2 minute idle time-out for the default /bin/bash shell. You can edit your ~/.bash_profile or /etc/profile file as follows to define a 5 minute idle time out:

# set a 5 min timeout policy for bash shell
readonly TMOUT
export TMOUT

Save and close the file. The readonly command is used to make variables and functions readonly i.e. you user cannot change the value of variable called TMOUT.

How Do I Disable TMOUT?

To disable auto-logout, just set the TMOUT to zero or unset it as follows:
$ export TMOUT=0
$ unset TMOUT
Please note that readonly variable can only be disabled by root in /etc/profile or ~/.bash_profile.

A Note About TCSH SHELL and OpenSSH Server/Client

SSH allows administrators to set an idle timeout interval in /etc/ssh/sshd_config file. TCSH user should use autologout variable. Please see our previous FAQ “Linux / UNIX Automatically Log BASH / TCSH / SSH Users Out After a Period of Inactivity” for more information.

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 5 comments… add one }
  • Rahul March 13, 2013, 8:49 am

    hi Vivek,

    I have searched through the net, but could not find a process for the gnome 2/3 screen to logoff root user on inactivity. If you know or find would you let me know of it?
    Also same funcationality on other Window managers if you know would help too.


  • Jason Kirby January 30, 2014, 2:26 pm

    I’d like to know if bash can be set to something other than exit after the TMOUT interval expires, for example, vlock. In our shop it would be better to leave them in their shell but just require their password for them to get back in.

  • Manoj December 17, 2014, 8:50 am

    Hi Admin,

    Thanks its working like a charm.

  • sigh May 11, 2016, 3:51 am

    Oh awesome I typed it readonly TMOUT and now I can’t modify the timeout variable….. Thanks for that. Not telling me how to put it back.

    • Jesus September 13, 2016, 3:02 pm

      Hahaha you twat

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , ,