In this guide, we showed you how to add users to Ubuntu 20.04 with adduser and visudo command utilities. There comes a time when you need to delete users and therefore this guide is the place that will show you how it is done.
Because we are using Ubuntu 20.04 in this guide, you will need to have already set up one or more users with root administrative privileges. If you haven’t already, you can set this up using this initial server setup guide for Ubuntu 20.04.
Delete Users on Ubuntu 20.04
When users are no longer needed, it is always a good idea to delete them for administrative and security reasons.
In case you want to delete the user itself, without deleting any of their files, simply type in the following deluser command as root:
If you are signed in as another non-root user with sudo privileges and you want to delete yet another user, you can type:
$ sudo deluser newuser
There are cases where you also need to remove the user’s file usually in their home directory. You can do this by using the following command:
$ sudo deluser --remove-home newuser
If you had previously configured sudo privileges for the user you deleted, be sure to remove the relevant line again by typing:
$ sudo visudo
Then delete the corresponding line from the /etc/sudoers
root ALL=(ALL:ALL) ALL
newuser ALL=(ALL:ALL) ALL # Delete this
This stops a new user created with the same name from accidentally inheriting sudo privileges from a previous user.
You can find out more about setting root privileges using visudo or creating a new user entirely from this guide on how to add users to Ubuntu 20.04. There is also a comprehensive guide on how to delete groups in Linux using groupdel and delgroup utilities that is a must-read.