[RHCE] Automatically. Logging off users after n secondsin unix
m/c.
Jon Carnes
jonc at nc.rr.com
Fri Jan 23 10:10:23 EST 2004
On Fri, 2004-01-23 at 06:28, Sampat Dharmesh wrote:
> Hi Friends,
>
> I have a small querry, I want to logoff a user after N sec. of login.
> irrespective of the activity he performs.I found of similar option
> TMOUT but that's specific to user's Inactivity incase user is active
> he wont get logged off.Due provide a solution if any one knows.
>
> Regards,
> -Sampat.
>
I don't know of any utility that does this, but if your users are
running the bash shell you could always create a file like so:
vi /usr/local/sbin/autologout
# Automatically log off user after 600 seconds
sleep 540; echo "Auto logout proceeding in 60seconds"
sleep 60; kill -9 $PPID
chmod a+x /usr/local/sbin/autologout
In bash (on Red Hat Linux and probably other OS's as well) the PPID
variable contains the startup shells Process ID Number. Killing that
process logs the user out.
To have it auto-magically work for a user but the following line in at
the bottom of the their .bashrc file:
/usr/local/sbin/autologout &
The process will kick off and run in the background and after 4 minutes
give them a warning, then after one more minute it will log them off.
The weakness to doing it this way is that the user (if they are smart)
can look for the process and kill it - since the process runs as the
user. To avoid this, you would have to construct a daemon run via root
that monitored for logins.
You could easily write a script that ran once a minute or once every 10
minutes (out of cron). The script would look for logins and the time of
the login, then compare that time to the current time - if limit is
past, log them off.
Jon
More information about the RHCE
mailing list