userdel (Delete User)
The userdel
(USER DELete) command is used to delete existing users. With the -r
option, you can delete its home directory at the same time. To run this command, you need to run it with superuser privileges.
Delete a user with its home directory
To check the current user status, run the grep
command. As we created three users (user_a, user_b, user_c), you can see the three profiles by running the grep
command with "user" as the search word.
grep user /etc/passwd
user_a:x:1001:1001::/home/user_a:/bin/sh
user_b:x:1002:1002::/home/user_b:/bin/sh
user_c:x:1003:1003::/home/user_c:/bin/sh
Run the following userdel
command to delete user_c with their home directory.
sudo userdel -r user_c
You may see a message saying "mail spool not found", but this is nothing to worry about.
userdel: user_c mail spool (/var/mail/user_c) not found
To confirm that user_c is successfully deleted, run the grep
command again.
grep user /etc/passwd
user_a:x:1001:1001::/home/user_a:/bin/sh
user_b:x:1002:1002::/home/user_b:/bin/sh