Delete user account using the USERDEL command in Linux

Home > Search > Linux commands
  by

The userdel command can be used to delete a user account. In this example, John Doe's user account is deleted.

[root@server1 ~]# userdel john.doe

 

The userdel command without any options will not delete the users home directory. In this example, the files and folders at and below /home/john.doe will not be removed from the system.

[root@server1 ~]# ls -l /home/john.doe
total 44
drwxr-xr-x 2 john.doe john.doe 4096 Apr 16 12:07 Desktop
drwxr-xr-x 2 john.doe john.doe 4096 Mar 12 12:48 Documents
drwxr-xr-x 2 john.doe john.doe 4096 Mar 16 21:00 Downloads
drwxr-xr-x 2 john.doe john.doe 4096 Mar  5 08:34 Music
drwxr-xr-x 2 john.doe john.doe 4096 Apr 15 19:25 Pictures
drwxr-xr-x 2 john.doe john.doe 4096 Mar  5 08:34 Public
drwxr-xr-x 2 john.doe john.doe 4096 Mar  5 08:34 Templates
drwxr-xr-x 2 john.doe john.doe 4096 Mar  5 08:34 Videos

 


Delete home directory

The -r or --remove option can be used to delete the files and folders at and below the users home directory. In this example, John Doe's users account and home directory is deleted.

[root@server1 ~]# userdel -r john.doe

 


Delete even if the user is signed in

If John Doe is currently signed in, an error will appear when attempting to delete John Doe's account.

[root@server1 ~]# userdel john.doe
userdel: user john.doe is currently used by process 15339

 

The -f or --force option can be used to delete an account even if the user is currently signed in. This will also delete the files and folders at and below the users home directory.

[root@server1 ~]# userdel -f john.doe

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments