Linux System Administration

0 of 83 lessons complete (0%)

Managing User Accounts

Removing Users

You don’t have access to this lesson

Please register or sign in to access the course content.

Commands for Removing Users and Groups in Unix-like Systems

CommandPurposeKey OptionsExample
userdelRemove a user account from the system-r (remove home directory)Example:
1. Delete user john and remove home directory: sudo userdel -r john
deluserRemove a user account (alternative to userdel)NoneExample:
1. Delete user john: sudo deluser john
gpasswdRemove 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
delgroupDelete a group from the system--system (delete system group)Example:
1. Delete the testgroup group: sudo delgroup testgroup

Example Usage:

  1. 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.
  2. 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.
  3. 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.
  4. 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.