Adding and removing user accounts is a daily task for a Linux system administrator. Ubuntu is one of the most popular distributions used in the Enterprise environment where the delete or remove user account is a daily task too. Removing or deleting a user account in Ubuntu requires administrative privileges which are generally provided with the root user. A user account can be deleted in different ways and with different options in Ubuntu. In this tutorial, we examine how to delete a user account by deleting its home directory, removing permissions, etc.
List User Accounts
Before deleting or removing a Ubuntu user account we can list currently existing accounts. The users are stored in the
/etc/passwd where the first column is the user account name. We can list existing user accounts with the cat command like below.
$ cat /etc/passwd
Remove/Delete User Account with deluser Command
The official command to delete or remove user account from the Ubuntu is the
deluser command. The user account name should be provided to the deluser command. Also we require privileges to delete user account which can be provided by logging in root user or by using the
sudo command as a regular user.
$ sudo deluser ismail
Remove/Delete User Account with deluser Removing User Home Directory
The deluser command does not delete the user account home directory by default. In order to delete the user account home directory, the
--remove-home option should be provided like below. In the following example while deleting the user “ismail” also its home directory “/home/ismail” will be deleted.
$ sudo deluser --remove-home ismail
Remove/Delete User Account with GUI
The user management provided via the
Settings tool in Ubuntu. First we open the Settings tool which can be opened in different ways like clicking dash and then typing
settings which is listed like below.
In the Settings navigate to the
Users from the left pane and click to the
Unlock button in order to authenticate as sudo user to get required privielges to delete account.
Provide the current user password to get privileges.
In the following step we select the user we want to delete from the list of users. In this case we select the user named
ahmet to delete it and click to the
Remove User... button in the right left corner.
We asked for if we want to delete the users files or we want to keep them. This is the same operation of deleting the user home directory. In this example we
Delete Files for the user ahmet.
Verify User Account Has Been Deleted From Ubuntu
We can verify if the user has been deleted successfully or check if a specific user account exists in Ubuntu by using the grep command. Just provide the user name to the grep command to filter
passwd file like below. In the following example, we check if the user ahmet deleted successfully and if exists in the “/etc/passwd” file.
$ grep '^ahmet' /etc/passwd
Temporarily Disable User Account
Deleting a user in Ubuntu removes the account and its home folder completely where they can not be recovered in a regular way. But if we want to revert them back later but do prevent access for specific time period we can disable account. The
usermod command can be used to disable an account in Ubuntu.
$ sudo usermod -L -e 1 ahmet
Alternatively, we can specify the disable period where after the specified data the user account is enabled automatically. In the following example, we disable the account to the 2021-12-01. After 2021-12-01 the account is enabled automatically.
$ sudo usermod -e 2021-12-01 ahmet