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:
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/passwd
file - User password information: stored in the
/etc/shadow
file - Basic user group information: stored in the
/etc/group
file - User group information: stored in the
/etc/gshadow
file - User personal files: The home directory is located at
/home/username
by 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:
Additional 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:
To delete all files of a user:
3.3 The difference
userdel
is a binary file in the system, whiledeluser
is a script file.deluser
is more low-level thanuserdel
, providing more comprehensive options for deleting users and groups.userdel
is 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 who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me 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!