How to delete a user in Linux?

QuestionsQuestions8 SkillsProDec, 18 2025
0115

To delete a user in Linux, you use the userdel command. Since this is an administrative action, you must use sudo.

There are two main ways to do this:

1. Delete Only the User

If you want to remove the user but keep their files and home directory, use:

sudo userdel jack

2. Delete the User AND their Home Directory

If you want to completely remove the user along with their home directory and mail spool (cleaning up all their files), use the -r (recursive) flag:

sudo userdel -r jack

This is the most common way to fully remove a user from the system.


Key Tips for Deleting Users:

  • Check if they are logged in: You cannot delete a user who is currently logged in. You may need to kill their processes first using sudo killall -u username.
  • Check Groups: When you delete a user, the primary group created for them (the User Private Group) is also automatically deleted if no other users belong to it.
  • Verification: After deleting, you can verify the user is gone by trying to check their ID:
    id jack
    If it says no such user, the deletion was successful!

Since you just created jack in your current lab, you can try these commands if you want to practice, but remember that the lab instructions might expect jack to exist for the next steps!

0 Comments

no data
Be the first to share your comment!