1
I have been tasked with removing departed employees' local *nix accounts. In almost all cases, userdel -r <username>
works like a charm. However there are a few cases where the user in question was removed uncleanly on a prior date, leaving their account non-existent but with a presence in the /etc/group file and a home directory. When the task comes to me to remove their user from the system, I find that the user doesn't exist, but I still need to remove these remnants. In this case, userdel -r <username>
prints userdel: user '<username>' does not exist
, and the orphaned group entries, mail spool, home directory etc are not removed.
I could whip up a script to check home, group, and mail spool myself, but I'd rather use an existing utility if it exists. That utility can be a shell command or an Ansible module.
I'm given the username to purge, and that can be assumed correct, though case insensitivity would be a bonus. If there's a safe way to find and correct all non-existent users without an input, that would be even better, as it would save me from having to rework previous tasks.
I've found that I can add the user and then remove them with the -r flag, but that feels somewhat unclean. It's preferable to writing the script I mentioned in the second paragraph, however. – Wazoople – 2019-04-19T17:57:53.827