Difference between userdel and deluser in Linux System
1. Purpose
In this post, I will explain the difference between the userdel and deluser commands in Linux Operating Systems.
2. Environment
- Ubuntu System
3. What is the difference between the userdel and deluser in Linux?
3.1 What is userdel?
The Linux userdel command is used to delete user accounts. This command can only be executed by root users. userdel can delete user accounts and related files. If no parameters are added, only the user account will be deleted, and the related files will not be removed.
The syntax of this command is:
userdel [-r] [user_account]The -r option deletes the user’s home directory along with the user.
User information is stored in the following files:
- Basic user information: stored in the
/etc/passwdfile - User password information: stored in the
/etc/shadowfile - Basic user group information: stored in the
/etc/groupfile - User group information: stored in the
/etc/gshadowfile - User personal files: The home directory is located at
/home/usernameby default, and the mailbox is located at/var/spool/mail/username
The userdel command removes the data related to the specified user from these files.
3.2 What is deluser?
The deluser command is also used to delete users. While usermod is often recommended for removing a user from a group, deluser is the preferred method due to its richer options and more powerful functionality.
To delete a normal user:
[root@linux ~]# deluser mikeAdditional options can be specified when deleting a user:
--remove-home: Delete the user’s home directory and mailbox.--remove-all-files: Delete all files owned by the user.--backup: Back up files before deleting.--backup-to<DIR>: Specify the destination directory for the backup. The default is the current directory.--system: Delete only if the user is a system user.
To delete a user from a group:
[root@linux ~]# deluser mike admingroupTo delete all files of a user:
[root@linux ~]# deluser --remove-all-files mike3.3 The difference
userdelis a binary file in the system, whiledeluseris a script file.deluseris more low-level thanuserdel, providing more comprehensive options for deleting users and groups.userdelis a higher-level command, offering a more straightforward way to delete users.
4. Summary
In this post, I explained the differences between the userdel and deluser commands in Linux. While both commands are used to delete user accounts, deluser offers more advanced options and flexibility compared to userdel. Understanding these differences can help you choose the right tool for managing user accounts on your Linux system.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!