Idle ssh users

Rick Stevens rstevens at vitalstream.com
Thu Jan 26 19:17:20 UTC 2006


On Thu, 2006-01-26 at 11:22 -0700, redhat at buglecreek.com wrote:
> On occasion we have have people login via ssh to some of our RH linux
> systems and they do not log out.  When doing a "w" or
> "who" we see idle connections for days sometimes.  What is the
> recommended way to log these users out?  Is there a better way than just
> killing the users ssh process?

Not really.  You can write a script that parses the output of the "last"
or "who" commands and kills off the processes involved.  For example:

    #!/bin/bash
    PATH=$PATH;/usr/bin;/bin
    WHOLIST=`who -u`
    for LINE in $WHOLIST; do
	echo $LINE | awk '{if (index($6, "old")) system("kill "$7);}'
    done

would kill any user's login process that had been idle for over a day.
I'd set that up as a shell script and run a cron job for it every, oh,
four hours or so, depending on what you want to do.

See "info who" for details on the "-u" option.

----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-  You know the old saying--any technology sufficiently advanced is  -
-               indistinguishable from a Perl script                 -
-                                 --Programming Perl, 2nd Edition    -
----------------------------------------------------------------------




More information about the Redhat-install-list mailing list