CIS120 Linux Fundamentals by Scott Shaper

groupadd and groupdel Commands

Think of groupadd and groupdel as the official ways to create and remove groups on a Linux system. groupadd adds a new line to /etc/group (and often creates an entry in /etc/gshadow). groupdel removes that line. Only root (or someone with the right sudo privileges) can run these commands. Use them when you need a new group for permissions (e.g. "developers" or "editors") or when you're cleaning up a group that's no longer needed.

Quick Reference

Command What It Does Common Use
groupadd Creates a new group Adding groups for file permissions or team access
groupdel Removes a group Deleting groups that are no longer needed

When to Use These Commands

Note: You need root privileges. Use sudo groupadd ... and sudo groupdel ....

groupadd: Common Options

Option What It Does When to Use It
-g GID Set the group ID (must be unique) When you need a specific GID
-r Create a system group (uses a low GID from a system range) For daemons or system services

groupadd: Practical Examples

Create a normal group

# Create a group named developers
sudo groupadd developers

The system picks the next available GID. Add users with usermod -aG developers username.

Create a group with a specific GID

# Create group with GID 2000
sudo groupadd -g 2000 developers

Create a system group

# Create a system group (e.g. for an application)
sudo groupadd -r myapp

groupdel: Practical Examples

Remove a group

# Remove the group (only if no user has it as primary group)
sudo groupdel developers

groupdel will fail if any user in /etc/passwd has this group as their primary group (GID). Remove users from the group or change their primary group first, then delete the group.

Tips for Success

Common Mistakes to Avoid

Best Practices