Automatic Logouts with Screen
Server - CentOS


The screen application can be used to create automatic logouts, thus ensuring that an account has not been left logged in and create a security issue. Install it with this command:

 

yum install -y screen

 

Edit the /etc/profile which impacts all users.

 

Place this line at the top of the file to ensure the functioning of the file.

trap "" 1 2 3 15

 

At the bottom of the same file add these lines. When a user logs in they will get a message that login will complete in 5 seconds. You can adjust that time with the sleep time.

 

SCREENEXEC="screen"

if [ -w $(tty) ]; then

trap "exec $SCREENEXEC" 1 2 3 15

echo -n 'Starting session in 5 seconds'

sleep 5

exec $SCREENEXEC

fi

 

You will also need to modify the /etc/screenrc file and add these lines at the end.

 

idle 300 quit

autodetach off

 

Those settings provide a logout after 300 seconds of idle time. Modify that setting to one that makes sense for you. When you are logged in you will see the screen process.

 

root 4566 0.0 0.0 4924 996 pts/1 Ss+ 11:07 0:00 screen

root 4593 0.0 0.0 5056 1184 ? Rs 11:07 0:00 SCREEN

 

When the login is inactive for the time period indicated in the idle line, the login is automatically closed.

 

Last login: Mon Dec 19 10:57:13 2011 from 192.168.5.103

Starting session in 10 seconds[screen is terminating]

Connection to 192.168.5.98 closed.

mike@mk:~$