How to Delete a user account on Ubuntu Server 20.04

If you no longer need a user account, it is good idea to delete that account.

Step 1 : You will need super user or root privileges to delete a group from the Ubuntu server. Follow these steps to delete the user account

# sudo deluser --remove-home <username>
sudo deluser --remove-home tutorial

–remove-home : This will delete the user account named tutorial and also remove the home and mail spool directories associated with tutorial.

Step 2 : Enter your password to complete deluser with root privileges

To keep a backup of user files before removing the home directory and any other files.

sudo deluser --backup --remove-home tutorial

Step 3 : When called with the –group option, the deluser command will remove the group. Similarly, when called with two non-option arguments, the deluser command will try to remove a user from a specific group

deluser devtutorial groupdev # this will remove user devtutorial from group groupdev
deluser --group groupdev # this will remove a group

Step 4 : If you want to disable the user account rather than delete it, you can do it with the following commands

sudo usermod --expiredate 1 devtutorial # disable the user account devtutorial
sudo usermod --expiredate "" devtutorial # re-enable user account devtutorial
sudo usermod -e YYYY-MM-DD devtutorial # specify expiry date

Add Comment