Removing Users
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
johnand remove their home directory:bashCopy codesudo userdel -r johnThis command deletes the userjohnand removes their home directory.
- Delete user
- Remove a User with
deluser:- Delete user
john:bashCopy codesudo deluser johnThis command deletes the userjohnfrom the system. It does not remove the user’s home directory or files by default.
- Delete user
- Remove a User from a Group with
gpasswd:- Remove user
johnfrom thedevelopersgroup:bashCopy codesudo gpasswd -d john developersThis command removes the userjohnfrom thedevelopersgroup.
- Remove user
- Delete a Group with
delgroup:- Delete the
testgroupgroup:bashCopy codesudo delgroup testgroupThis command deletes thetestgroupgroup from the system. Note thatdelgroupis typically used for removing non-system groups.
- Delete the
