Bash Configure Automatic Logout [ Linux / Unix / Apple OS X ]

last updated in Categories , ,

How can I configure automatic logout for my bash shell under Unix / Apple OS X / Linux operating systems?\

You can configure any modern shell including bash to auto logout. Please note that autologout will only work for the foreground process. For example, if you left your session idle the automatic shell logout will occur. But, if an interactive process such as top command or a vi text editor session is left idle, then automatic logout would not occur.

Configuration

Add the following lines to your bash startup file such as $HOME/.bash_profile or create a new bash shell script called timout-settings.sh in the /etc/profile.d directory:

## append in $HOME/.bash_profile
## 300 seconds == 5 minutes ##
TMOUT=300
readonly TMOUT
export TMOUT

OR /etc/profile.d/timout-settings.sh

#!/bin/bash
## 300 seconds == 5 minutes ##
TMOUT=300
readonly TMOUT
export TMOUT

Save and close the file.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

1 comment

    Have a question? Post it on our forum!