Home

Deleting Linux users with userdel

When you need to remove a user account on Ubuntu (or any other Linux distro), userdel is the tool. It's a small command with just a few flags, and you'll need root or sudo to run it.

Just remove the user

To remove the user but leave their home directory and files in place:

bash
sudo userdel user_name

The user is gone, but the home directory under /home/user_name and any files they owned are still there. You can clean those up by hand later if you want.

Remove the user and their home directory

Pass -r to also wipe the user's home directory:

bash
sudo userdel -r user_name

Be careful with this — once you've blown away the home directory, anything that wasn't backed up is gone. If there's any chance you'll need their files (logs, scripts, dotfiles), keep the user removal and the cleanup as separate steps.

userdel only takes one user per invocation — if you need to remove several, run it once per name.