Setup Autologout on CentOS/RHEL

Scenario: How to setup autologout console and ssh session on CentOS/RHEL
System: CentOS/RHEL 6/7

By default on CentOS/RHEL fresh install system didn’t come with automatically logout, you must manually configure Linux system to automatically log users out after a period of inactivity.

Steps to set up system wide auto logout console and ssh session
1) Log in as root.
2) Create a new script file (to auto logout after 15 minutes),example we create

# vi /etc/profile.d/

readonly TMOUT
export TMOUT

Make executable,run..
# chmod +x /etc/profile.d/

3) Re-login or reboot your system to apply.

Steps to set up auto logout ssh session
1) Log in as root.
2) Edit /etc/ssh/sshd_config file, example we will set autologout after 15 minutes.
# vi /etc/ssh/sshd_config

Add/modify the following lines:

ClientAliveInterval 300
ClientAliveCountMax 3

Note: Explanation above -> (timeout interval = ClientAliveInterval x ClientAliveCountMax = 300s x 3 )
The meaning of the two parameters can be found in the man page of sshd_config

or setup like below for the same autologout after 15 minutes.

ClientAliveInterval 900
ClientAliveCountMax 0

3) Restart sshd service
CentOS/RHEL 7# systemctl restart sshd
CentOS/RHEL 6# service sshd restart

Leave a Reply

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