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
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
--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
--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!