How can an administrator find the UID of a user that's been deleted with the userdel
command?
-
Is the account already deleted?– Michael MrozekMay 14, 2012 at 15:56
-
@ Michael Mrozek yes.– SamMay 14, 2012 at 16:06
-
Is the home directory still around? An "ls -l" of that directory should show the UID, given that the entry from /etc/passwd is gone.– cjcMay 14, 2012 at 16:11
-
@cjc no! Home directory is deleted and the admin doesn't now which file belongs to that account.– SamMay 14, 2012 at 16:15
2 Answers
By looking at /etc/passwd
in the backups taken of your system from the day/week/period before the user deletion.
If userdel
was used with -r, then both the home directory and user's mail spool have gone. If it wasn't used with -r, check for the user's mail spool, or perhaps a crontab if you're very lucky.
If there are no backups, and no obvious files owned by that user you can check, then you'll need to scout around places like /tmp
and look for files with UID's as owners and try and work it out - but really, your backup is your best bet.
Edit: as jw013 points out you could also use find / -nouser
to find files which have no matching user for the file's UID.
-
2You can try:
find / -uid <UID>
to find all files owned by the user.-uid
is an option on GNU find at least. May 14, 2012 at 17:31 -
12
-
4@jw013 this approach works only if you have deleted only one user from system but if you have a system with 300 users that worked for 5 years with tens of deleted users you can't use this method at all.– SamMay 16, 2012 at 6:40
-
2This is an example that only describes a situation in which your suggestion doesn't work nothing more.– SamMay 16, 2012 at 14:03
-
2Well, -nouser in combination with -mtime would let you find out the most recently active unowned files, which would probably help. May 16, 2012 at 20:07
If there are 10 users and 1 deleted user, you could check /etc/passwd for which UID from 1000 and up is missing.
-
1Not 100% reliable, particularly if more than one account has been deleted, but likely to be quick if it works. May 15, 2012 at 20:42