Hello Linux Geeksters. In this short article I will show you how to set the terminal to auto close, after it has been idle for a specified number of seconds. This is very good if you accidentally remain logged in as root and leave the computer idle for a time.
In this article I will show you how to make your terminal auto close after 120 seconds of idleness. This guide is generical and works on all the popular Linux systems, including: Ubuntu, Linux Mint, Debian, Elementary OS, Pear OS, Fedora, OpenSUSE, Mageia including Arch Linux.
Append TMOUT=120 to the /etc/bash.bashrc file and export the variable. (replace 120 with any number of seconds ; we need root privileges in order to save changes in configuration files). Source the newly updated file, in order to load the changes:
$ sudo sh -c 'echo "export TMOUT=120" >> /etc/profile'
$ sudo source $HOME/.profile
This setting applies to all the users in the system, since it was written in the /etc/profile file. To set it only for your user, do:
$ echo "export TMOUT=120" >> $HOME/.profile
$ source /etc/profile
The ultimate geekery: Set the terminal to auto close after 120 seconds of idleness, only the if the user logged in is root:
$ sudo sh -c 'echo "[ $USER = root ] && export TMOUT=120" >> /etc/profile'
$ sudo source /etc/profile