groupadd
Overview
groupadd creates a new group entry in the local group database (/etc/group, and /etc/gshadow when used). Groups grant shared file access and sudo/role membership without sharing login accounts. On Ubuntu, interactive admins sometimes use addgroup; automation should prefer groupadd for stable flags.
Syntax
sudo groupadd [options] GROUPCommon Options
| Option | Description |
|---|---|
-g GID, --gid |
Numeric GID |
-r, --system |
System group (GID from system range in login.defs) |
-f, --force |
Exit successfully if group already exists; still fails on GID conflict unless handled |
-K KEY=VAL |
Override /etc/login.defs defaults for this invocation |
-o, --non-unique |
Allow non-unique GID (usually avoid) |
-p PASSWORD |
Encrypted group password (rare; prefer no group passwords) |
-U USERS, --users |
Comma-separated user list to add (util-linux; version-dependent) |
Safety
- Pick GIDs deliberately when using NFS or shared storage; mismatched GIDs mean “same name, different access”.
- Do not reuse GIDs of deleted groups until you understand leftover file ownership on disk.
- Group passwords are an old pattern; modern sites use explicit membership instead.
- Naming collisions with system groups (
sudo,adm,disk,docker) are high risk — list first.
Key Use Cases
- Create application/shared-data groups (
appdata,deploy) - Create system groups for daemons
- Align GIDs across a fleet for shared filesystems
- Prepare groups before
useradd -G/usermod -aG
Examples with Explanations
Example: simple project group
sudo groupadd appdata
getent group appdataCreates the group with the next available GID from the user range.
Example: fixed GID for NFS fleet
sudo groupadd -g 12000 appdata
getent group appdataUse the same GID on every server that mounts the same export.
Example: system group for a daemon
sudo groupadd -r appsvc
getent group appsvcSystem GID range is defined in /etc/login.defs (SYS_GID_MIN / SYS_GID_MAX).
Example: create group then add members (-aG)
sudo groupadd deploy
sudo usermod -aG deploy alice
sudo usermod -aG deploy bob
getent group deploy
id aliceAlways append with usermod -aG so existing supplementary groups remain intact.
Example: Ubuntu interactive alternative
sudo addgroup designersDebian/Ubuntu helper; fine for humans, less ideal for exact GID control in scripts.
Example: idempotent-ish create in scripts
if ! getent group appdata >/dev/null; then
sudo groupadd -g 12000 appdata
fiOr experiment with groupadd -f carefully — still verify GID when identity matters.
Example: list and inspect
getent group | tail
getent group sudo
grep '^docker:' /etc/groupPrefer getent so NSS sources (LDAP) are included.
Notes & Pitfalls
- Name vs number: tools and NFS care about GID; humans care about names — keep them consistent across systems.
- Deleting groups (
groupdel) does not rewrite file ownership on disk — orphaned GIDs appear inls -ln. - Membership changes need re-login to appear in a user’s active session.
- Directory services: create groups in FreeIPA/LDAP when that is the source of truth.
docker/socket groups grant near-root power — treat membership as privileged.
Additional Resources
man groupaddman group(5)man login.defs