
It just happens that some users would eventually leave. In such a scenario, it is better to delete them. So, that they can no longer have the access to the system. It is the System Administrator’s work to keep things tidy. So, a System Administrator adds a user to a specific group when requested by the user. And, deletes them whenever required. We have already covered how to Add a user in Ubuntu . In this article, we cover how to Delete a user in Ubuntu.
The command-line utility which we utilize here is – deluser.
Note: As deleting a user require superuser privileges. So, if you don’t have one then, ask your System Administrator for further assistance.
Delete a user in Ubuntu
There are few things to consider before deleting a user. First, whether you want to delete all files and directories owned by the user. If so, then would you like to have a backup of those files and directories.
So, if you want to backup all files and directories before deleting a user then, use the following command in terminal –
sudo deluser <user_name> --remove-all-files --backup-to </path/to/backup-location/>
For instance, if we have a abc user and we want to backup files to the directory /home/$USER/Backup. Then, it would be –
sudo deluser abc --remove-all-files --backup-to /home/$USER/Backup
Note: Just ensure that, the directory or location must exist, where we can save our backup. In above example, we created a Backup directory first /home/$USER/Backup
mkdir /home/$USER/Backup
Second, if you don’t want to delete files owned by user then just use –
sudo deluser <user_name>
For instance, for the above example – it would be –
sudo deluser abc
In conclusion, we have covered how to delete a user in Ubuntu.
Additional Info –
There is one more option, which we thought should also be covered.
--remove-home
This would only remove HOME directory. And, it is different from –remove-all-files option. It shouldn’t be used with –remove-all-files option. Reason: –remove-all-files already covers home directory.