Solved

Dead/orphan users

Posted on 2003-12-05
3
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 9883825
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
ID: 9886075
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
ID: 9898536
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

690 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