Home > UNIX > How to KILL IDLE SESSIONS IN UNIX.

How to KILL IDLE SESSIONS IN UNIX.

July 2, 2013

 

Unix systems provide a number of ways that sysadmins can log off users when user login sessions are idle for more than a specified time. The choices differ, however, in how they define “idle” and in how they determine the length of time that a user has been idle.

Using TMOUT

The newer shells in the sh family (e.g., ksh and bash) provide a timeout variable, TMOUT, that can be used to end idle sessions. If TMOUT is set to any value greater than 0, the shell will end after a prescribed number of seconds have passed without command activity. Two of the most popular shells, ksh and bash, provide the TMOUT variable, but process the TMOUT limit a bit
differently. Bash counts down and exits the shell after $TMOUT seconds. Ksh, on the other hand, counts down $TMOUT seconds, warns the user about the impending timeout and then waits an additional 60 seconds before exiting the shell.

In one login session, type /bin/bash to enter a secondary shell and type the command “TMOUT=5”. After five seconds, your secondary shell will exit as shown
here:

bash$ TMOUT=5
bash$ timed out waiting for input: auto-logout

In a second login session, type /bin/ksh to enter a secondary shell and type the same “TMOUT=5” command. After five seconds, you should see the second line shown below and, after another sixty seconds, your shell with exit.

$ TMOUT=5
shell will timeout in 60 seconds due to inactivity
/bin/ksh: timed out waiting for input

You can set TMOUT in users’ dot files (e.g., ~/.profile) to establish timeout limits or in system files like /etc/profile that affect all users. If you were to add the command “export TMOUT=900” to one of these files, you would be setting your users’ idle timer to allow 15 minutes of inactivity before a session termination begins.

Advertisements
Categories: UNIX
%d bloggers like this: