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 log users out after a period of inactivity automatically. 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. In other words, your user cannot change the value of the variable called TMOUT. Consider this as a security feature.
Linux TMOUT To Automatically Log Users Out

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 user 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.


TMOUT is a bash variable to auto-logout Linux users when there isn’t any activity. When we set TMOUT value greater than zero, TMOUT is treated as the default timeout for the read command. The select command terminates if the input does not arrive after TMOUT seconds when information is coming from a terminal. In an interactive shell, the value is interpreted as the number of seconds to wait for a line of input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if a complete line of information does not arrive. Read bash man page for more information by typing the following man command:
$ man bash

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Rahul Mar 13, 2013 @ 8:49

    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 Jan 30, 2014 @ 14:26

    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 Dec 17, 2014 @ 8:50

    Hi Admin,

    Thanks its working like a charm.

  • sigh May 11, 2016 @ 3:51

    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 Sep 13, 2016 @ 15:02

      Hahaha you twat

  • Asif Saleem Apr 24, 2017 @ 12:58

    What would be impact on services which are running on this server ?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum