How To Delete Remove User Accounts In Linux?
How can I remove a Linux user account from Linux system. As you know user management in Linux requires root privileges. While removing user his home directory can be remove or preserved. As same with mail box. User mailbox can be preserved.
List Existing Accounts
Before removing or deleting an user account checking the existing of account can be useful. We can check whether given account exist with different ways. In this example we will use
chage command with
-l list option for user
$ chage -l ismail
chage: user 'ismail' does not exist in /etc/passwd
- chage will give information about specified user
- -l test will list users information
- As said before the user is removed so there is no information about the user.
Or we can print the
/etc/passwd in a formatted manner which only list user account names by using
$ cat /etc/passwd | cut -d ':' -f 1
Remove/Delete User Account with userdel Command
We can remove given user account with
userdel command like below. In this example we will remove user account named
ismail . As this is an administrative task we need root privileges which can be get with
$ sudo userdel ismail
- userdel will remove specified test user account
Remove/Delete User Account and Home Directory
The default behavior of the
userdel command is removing user account from user data which resides
/etc/passwd . This will not delete the user account home directory. If we want to remove the user account home directory while removing account with
userdel we should provide the
-r option. In this example we will delete the user account
test and its home directory.
$ sudo userdel -r test
Remove/Delete User Account with Home Directory and User Owned Files
In previous example we have deleted user account with its home directory. If we want to delete also user owned files and folders while remove user account we can use
userdel command with
-f option. In this example we will remove user account
ali and its home folder and owned files and folders those resides other than his home directory.
$ sudo userdel -r -f ali
Remove/Delete User Account Line From passwd File
We have an other less structured option to remove a user account. We can remove the line which user is defined from file
/etc/passwd . As this file contains user details this will remove user account. We can also remove password hash from