Ubuntu article thumbnail image.

How do you delete a user from a machine using the Ubuntu operating system?

To do this, you can use the userdel command native to Ubuntu. userdel is a low level utility for removing users that modifies the system account files, deleting any entry that refers to a given user name.

To delete a user, use this command (replace username with your user's name):

sudo userdel username

If the username supplied doesn't exist, the command will fail.

Then, you may also want to delete the /home directory associated with the deleted user account:

sudo rm -r /home/username

You can also achieve this by adding the -r or --remove flag to the userdel command. This will remove the user's home directory along with the home directory itself.

The command with the --remove flag attached would look like this:

sudo userdel --remove username

One caveat is that the userdel command will not allow you to delete a user if there are running processes that belong to that user. The -f or --force option can force the deletion of this account.

The command would look like this:

sudo userdel --force username

After using the userdel command, you should also manually go through your system files and verify that no files owned by the user remain.

Thanks for reading and happy coding!

About the author

Hi, I'm Nick Major. I'm a software developer from Wisconsin, United States.

I create free and premium courses, have published hundreds of informational coding articles, and am currently a Frontend Software Engineer at RoundingWell.

You can read more about me here.

Picture of Nick Major.