Chapter 4. User, Group and Permission

Userdel (Delete User)

Userdel (Delete User)
Tag:

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.

Command Line - INPUT
grep user /etc/passwd
Command Line - INTERACTIVE
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.

Command Line - INPUT
sudo userdel -r user_c

You may see a message saying "mail spool not found", but this is nothing to worry about.

Command Line - RESPONSE
userdel: user_c mail spool (/var/mail/user_c) not found

To confirm that user_c is successfully deleted, run the grep command again.

Command Line - INPUT
grep user /etc/passwd
Command Line - INTERACTIVE
user_a:x:1001:1001::/home/user_a:/bin/sh
user_b:x:1002:1002::/home/user_b:/bin/sh

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.

Command Line - INPUT
grep user /etc/passwd
Command Line - INTERACTIVE
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.

Command Line - INPUT
sudo userdel -r user_c

You may see a message saying "mail spool not found", but this is nothing to worry about.

Command Line - RESPONSE
userdel: user_c mail spool (/var/mail/user_c) not found

To confirm that user_c is successfully deleted, run the grep command again.

Command Line - INPUT
grep user /etc/passwd
Command Line - INTERACTIVE
user_a:x:1001:1001::/home/user_a:/bin/sh
user_b:x:1002:1002::/home/user_b:/bin/sh
Tag: