Quick Tip: Automatically Close Terminal After A Certain Time Of Inactivity

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.

Quick Tip: Automatically Close Terminal After A Certain Time Of Inactivity

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

Tagged with: , , , , , , , , , , ,
Posted in The Linux and Unix Articles!
2 comments on “Quick Tip: Automatically Close Terminal After A Certain Time Of Inactivity
  1. Oliver says:

    Hi Geekster,

    Thanks for the tipp. Really nice.
    By the way.. On the user settings you missed to change the folder for the profile file:
    Should be:

    $ echo “export TMOUT=120” >> $HOME/.profile

    $ source /$HOME/.profile

    Cheers Oliver

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!