Commands for Removing Users and Groups in Unix-like Systems
Command
Purpose
Key Options
Example
userdel
Remove a user account from the system
-r (remove home directory)
Example:
1. Delete user john and remove home directory: sudo userdel -r john
deluser
Remove a user account (alternative to userdel)
None
Example:
1. Delete user john: sudo deluser john
gpasswd
Remove a user from a group
-d user group (remove user from group)
Example:
1. Remove user john from the developers group: sudo gpasswd -d john developers
delgroup
Delete a group from the system
--system (delete system group)
Example:
1. Delete the testgroup group: sudo delgroup testgroup
Example Usage:
Remove a User with userdel:
Delete user john and remove their home directory:bashCopy codesudo userdel -r john This command deletes the user john and removes their home directory.
Remove a User with deluser:
Delete user john:bashCopy codesudo deluser john This command deletes the user john from the system. It does not remove the userÖs home directory or files by default.
Remove a User from a Group with gpasswd:
Remove user john from the developers group:bashCopy codesudo gpasswd -d john developers This command removes the user john from the developers group.
Delete a Group with delgroup:
Delete the testgroup group:bashCopy codesudo delgroup testgroup This command deletes the testgroup group from the system. Note that delgroup is typically used for removing non-system groups.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.
Leave a Reply