Bootstrap FreeKB - Linux Commands - userdel (delete user account)
Linux Commands - userdel (delete user account)

Updated:   |  Linux Commands articles

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

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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