How to Delete an Existing User in Linux

How to Delete an Existing User in Linux

Hey there, and welcome back to ProgramGuru.org! In this tutorial, we're going to learn how to delete a user from a Linux system. Don't worry if you're just starting out — we'll take it step-by-step and explain everything along the way.

Let’s say you created a user for testing or for someone who no longer needs access. You don’t want them to keep cluttering your system, right? So here’s how you can remove them cleanly and safely.

Step 1: Open the Terminal

You can open the terminal using Ctrl + Alt + T, or search for "Terminal" in your application menu.

Step 2: Check Existing Users

Before deleting a user, you might want to check who exists on the system.

cut -d: -f1 /etc/passwd
root
daemon
bin
sys
john
testuser

Here, we see a list of user accounts. Let's say we want to delete testuser.

Step 3: Delete the User

To delete a user, use the userdel command. You’ll need superuser (admin) privileges, so either log in as root or use sudo.

sudo userdel testuser

This removes the user from the system, but their files in the home directory still remain.

Step 4: Delete User and Home Directory (Optional)

If you want to remove the user and their home directory at the same time, use the -r option:

sudo userdel -r testuser

This will delete:

  • The user account
  • The user's home directory (like /home/testuser)
  • Mail spool and other user-owned files in typical locations

Step 5: Confirm Deletion

You can check if the user was deleted successfully:

id testuser
id: ‘testuser’: no such user

If you see that message, it means the user is gone!

Wrap Up

And that’s it! You’ve just learned how to delete a user from your Linux system. 🎉

To quickly recap:

  1. Use userdel to remove a user
  2. Add -r to also remove their home directory
  3. Always check with id username to confirm

Thanks for watching! If you found this helpful, don’t forget to check out other beginner-friendly Linux tutorials at ProgramGuru.org.