Why is the username still displayed even when it's been deleted using 'userdel' [duplicate]
I added a user with the adduser
command and then deleted it withuserdel
, but the username is still displayed in the home directory and in the switch account section.
- Why does this happen?
- How do I get rid of it?
By default, userdel
only deletes the user from /etc/passwd
. To remove their home directory too, you pass the -r
or --remove
flag.
Once the user has been removed using userdel
, you cannot retrospectively run userdel -r user
to remove the home directory; instead you need to delete the user's home directory yourself, for example by running
sudo rm -r /home/user
replacing user
with the username you want to remove.
If there is an entry for the user in /var/mail
, or whatever directory is defined for MAIL_DIR
in /etc/login.defs
(run grep MAIL_DIR /etc/login.defs
to check), you can delete that too.
Deleting the home directory should fix the switch account menu too, but I couldn't reproduce your issue on my Ubuntu MATE system. Perhaps rebooting after removing the user's home directory is also needed for you.
See also the more flexible tool deluser
.