Solved

Dead/orphan users

Posted on 2003-12-05
3
512 Views
Last Modified: 2013-12-15
Is there an easy method to clean up dead or orphan users.  I have some users log on to a linux server, but don't exit cleanly.  I'm not an expert on linux, but the box is being used as a proxy, but there are users who log on to configure or restart certain services and don't exit cleanly.  I would like to know if there is some method available to clean up orphan user sessions.
pipporosso
0
Comment
Question by:pipporosso
3 Comments
 
LVL 40

Expert Comment

by:jlevie
Comment Utility
If you look at the process list and find their shell you can kill that and "log them out".  As an example to kill the session for user jtest I'd do:

# ps -ef | grep jtest | grep -v grep
jtest     4100  4098  0 12:06 ?        00:00:00 /usr/sbin/sshd
jtest     4102  4100  0 12:06 pts/1    00:00:00 -bash
# kill -9 4102
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
See if you have the program pkill on your system. On my SuSE system it was installed with the ps package. pkill can be used to kill all processes that are owned by a specified user. This example kills all processes owned by the user "test"

pkill -9 -U test

You need to be root in order to kill processes owned by other users.
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 25 total points
Comment Utility
Just another tiny note  -If the STIME - start time is before today when you use 'ps -ef', then it will give the date that the process was started.

Processes that probably shouldn't be more than a day old include sshd, bash and probably a few others.

If you first identify the processes that should be killed, then you can run a cron daemon process to kill all of these processes off at say 23:59.....and all the processes that you want to delete that are over one day old.

An example:

ps -ef | grep Nov | grep bash


will list all bash processes older than today.

if you then | this through awk, and then /bin/sh, you can kill off all bash processes older than today:

ps -ef | grep Nov | grep bash | awk {'print "kill -9 " $2'} | /bin/sh


****Always run the command without the | /bin/sh  first to check that the commands printed to the screen are the commands that you actually want the shell to run.

Then repeat this process for all other processes that you want to kill that are over 1 day old:)

HTH:)




0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now