1755434 Members
3404 Online
108832 Solutions
New Discussion юеВ

Deleting multiple users

 
SOLVED
Go to solution
NateJones
Occasional Advisor

Deleting multiple users

Hello,

Can someone tell me the proper method for removing large numbers of users from /etc/passwd? This is a trusted system, and all users to be removed have the same group id.

Thanks!
Nate
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Deleting multiple users

Hi Nate:

Use 'userdel'. See the manpages for more details. You could do:

#!/usr/bin/sh
while read USER
do
userdel -r ${USER}
RC=$?
if [ "${RC}" != 0 ]; then
echo "error ${RC} for ${USER}"
else
echo "${USER} deleted_OK"
fi
done < myuserlist

...where "myuserlist" contains the user name to be deleted -- one name per line in the file.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Deleting multiple users

How about a for loop with the "userdel" command:

for USER in `cat userlist`
do
userdel $USER
done

Or something similar.


Pete

Pete
Jeff_Traigle
Honored Contributor

Re: Deleting multiple users

I'd be reluctant to use the -r option on userdel unless you are 100% sure that they have unique isolated home directories. Although I typically don't use it, I did once at my last job ( I plead temporary insanity) and it just happened that user's home directory was right in the middle of an application directory. Removed the user and a good portion of the application along with him.
--
Jeff Traigle
NateJones
Occasional Advisor

Re: Deleting multiple users

Dang you guys are fast! Thanks much, you're script is exactly what I needed.

Nate
NateJones
Occasional Advisor

Re: Deleting multiple users

Thanks Jeff. I took James' advice and read the manpages, and did catch the -r switch. It would have indeed been distastrous for us as all users share the same home directory.

Nate