Practice Setup
Linux Architecture
Basic Commands
Basic file management or operations on file
User administration
Linux Interview Questions




Basically this command is used to delete the user. Observe the following examples to get more knowledge on userdel command.



Deleting the user account:

[root@sys2 ~]# userdel steve
[root@sys2 ~]# useradd steve


useradd: warning: the home directory already exists.

Not copying any file from skel directory into it.

Creating mailbox file: File exists

In the above few lines. We remove the user steve and again tried to add the user steve. But the user cannot be created because the home directory exists.



using userdel command alone we can delete the user but not the home directories of the user.



Deleting the user account along its home directory:

Using ‘-r’ option with userdel command we can delete the user account along with its home directory.

[root@sys2 ~]# userdel -r steve


Check the appropriate directories weather they are deleted or not.



Make sure that you have a backup of users data before using this option.



Deleting the user forcefully:

Sometimes when we rare trying to remove the user they can’t delete because they are already logged in or any process belongs to the particular user is running in the background.


For example the user steve is logged in but, I am trying to delete the user steve as shown delow.

[root@sys2 ~]# userdel -r steve
userdel: user steve is currently logged in


To delete the user forcefully we use “-f ‘ option with userdel command .

[root@sys2 ~]# userdel -f steve
[root@sys2 ~]# grep steve /etc/passwd



Kill all the process of user before deleting the particular user.



Topic review through questions: