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 userjohn
and removes their home directory.
- Delete user
- Remove a User with
deluser
:- Delete user
john
:bashCopy codesudo deluser john
This command deletes the userjohn
from 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
john
from thedevelopers
group:bashCopy codesudo gpasswd -d john developers
This command removes the userjohn
from thedevelopers
group.
- Remove user
- Delete a Group with
delgroup
:- Delete the
testgroup
group:bashCopy codesudo delgroup testgroup
This command deletes thetestgroup
group from the system. Note thatdelgroup
is typically used for removing non-system groups.
- Delete the