groupadd is the low-level Linux administration command that creates a new local group on the system, assigns it a group identifier (GID) and writes the entry into /etc/group and /etc/gshadow. In Linux permissions, groups are the middle layer of the classic owner, group and others model, so groupadd is usually the first step when several accounts need shared access to files, devices or administrative privileges.
The command belongs to the shadow-utils package (called passwd or shadow on some distributions) together with useradd, usermod and userdel. It only creates the group definition; it does not add members by default and does not change any file ownership, which is why it is normally combined with usermod -aG, gpasswd and chgrp.
How groupadd creates a group
When groupadd runs, it validates the requested name, picks or verifies a GID and then appends one line to each group database under a lock. It must run with root privileges, typically through sudo, because both target files are writable only by root and /etc/gshadow is not world-readable.
The sequence is short but strict. groupadd first reads /etc/login.defs for the GID ranges, then takes the lock files /etc/group.lock and /etc/gshadow.lock, writes temporary copies and renames them into place. This atomic replace pattern prevents a half-written group file if the system loses power or two administrators run account tools at the same moment.
The table below shows what each file receives after a command such as groupadd -g 2001 developers.
| File | Role | Example content |
|---|---|---|
| /etc/group | Public group database | developers:x:2001: |
| /etc/gshadow | Group passwords and administrators | developers:!:: |
| /etc/login.defs | Read only: GID ranges and defaults | GID_MIN 1000 |
| Lock files | Prevent concurrent edits | /etc/group.lock |
The x in the password field of /etc/group means the real value lives in /etc/gshadow, where ! marks a locked group password. Group passwords are rarely used today; access is granted through membership lists rather than through the newgrp password prompt.
Key groupadd options and GID ranges
Most invocations need only a name, but a handful of options control how the GID is chosen and where the group is written. The following options are available in current shadow-utils releases.
| Option | Effect | Typical use |
|---|---|---|
| -g GID | Uses a specific numeric GID | Matching GIDs across servers |
| -r | Creates a system group from the system range | Service accounts and daemons |
| -f | Exits successfully if the group already exists | Idempotent scripts |
| -o | Allows a duplicate GID with -g | Rare legacy aliasing |
| -K KEY=VALUE | Overrides a login.defs value once | Custom GID range for one call |
| -R CHROOT_DIR | Applies changes inside a chroot | Building images or rescue work |
| -U users | Adds listed users as members | Recent shadow-utils versions only |
Without -g, groupadd allocates the lowest free GID above the highest one in use within the configured range. Regular groups come from GID_MIN to GID_MAX, while -r draws from the system range below 1000, usually allocated downward from SYS_GID_MAX.
| Range | Values | Purpose |
|---|---|---|
| Root group | 0 | Reserved for root |
| System groups | 101-999 | Daemons, devices, packaged services |
| Regular groups | 1000-60000 | People, teams and projects |
| Special values | 65534 | nogroup or nobody, overflow GID |
Exact limits are distribution-specific and are defined in /etc/login.defs; older Red Hat releases started regular GIDs at 500. Group names should start with a lowercase letter or underscore, contain only lowercase letters, digits, hyphens and underscores, and stay within 32 characters for compatibility.
groupadd compared with related account tools
groupadd covers only group creation; neighboring commands handle membership, renaming, deletion and ownership. Knowing the boundary avoids the common belief that creating a group automatically grants anyone access to anything.
| Command | What it does | Relation to groupadd |
|---|---|---|
| groupadd | Creates a group and GID | Starting point |
| groupmod | Renames a group or changes its GID | Modifies what groupadd created |
| groupdel | Removes a group | Reverses groupadd |
| usermod -aG | Appends a user to supplementary groups | Adds members afterward |
| gpasswd | Manages members and group administrators | Alternative membership tool |
| chgrp | Changes the group owner of files | Applies the group to resources |
| addgroup | Debian and Ubuntu interactive wrapper | Calls groupadd with policy defaults |
On Debian-based systems, addgroup reads /etc/adduser.conf and enforces naming policy, which makes it friendlier for interactive use. In scripts and configuration management, groupadd is preferred because its behavior and exit codes are consistent across distributions.
Using groupadd in practice
A typical shared-directory setup uses groupadd together with membership and permission commands. The sequence below creates a team group, adds members, assigns a directory and sets the setgid bit so new files inherit the group.
- Create the group:
sudo groupadd -g 2001 developers. - Add members:
sudo usermod -aG developers alicefor each user. - Assign the directory:
sudo chgrp developers /srv/project. - Set permissions:
sudo chmod 2775 /srv/projectfor group write and setgid inheritance. - Ask members to log in again so the new membership takes effect.
Membership is read at login time and stored in the process credentials, so running sessions do not see a new group. Users can start a new login shell, run newgrp developers for one shell, or verify the result with id and getent group developers.
In automation, groupadd -f or a prior getent group check keeps a play idempotent. When the same group exists on many servers sharing NFS storage, always pass an explicit -g, because mismatched GIDs make files appear to belong to the wrong group on other hosts.
Limitations and common mistakes
groupadd edits only the local files database. Groups defined in LDAP, FreeIPA or Active Directory through SSSD are invisible to it, and creating a local group with the same name or GID as a directory group causes confusing name resolution.
The exit status is useful for diagnosing failures in scripts. The most frequent errors and their fixes are summarized below.
| Symptom | Likely cause | Fix |
|---|---|---|
| Exit code 9 | Group name already exists | Use -f or choose another name |
| Exit code 4 | Requested GID already in use | Pick a free GID or add -o deliberately |
| Exit code 3 | Invalid name or argument | Use lowercase letters, digits, hyphens |
| Exit code 10 | Cannot lock or update group file | Remove stale locks, check disk and permissions |
| Permission denied | Not running as root | Run the command with sudo |
- Using
usermod -Gwithout-areplaces all supplementary groups instead of adding one. - Editing
/etc/groupby hand skips locking and gshadow; prefer vigr if manual edits are unavoidable. - A user belongs to at most 65,536 supplementary groups in recent kernels, but NFS with AUTH_SYS passes only 16.
The simple explanation
A Linux computer controls who may open which files. Besides individual people, it also knows about named teams called groups. groupadd is the command an administrator types to create a new team and give it a number the system uses internally.
Creating the team is like printing a new badge type for an office. Nobody carries the badge yet, and no door accepts it yet. The administrator still has to hand badges to people and tell each door which badge opens it. Once that is done, everyone on the team can share the same folders without sharing passwords.
How it is used in practice
A small web agency runs a Linux server where four developers maintain client websites under /var/www. Previously every file belonged to a single shared account, so nobody could tell who changed what. The administrator creates a dedicated group with sudo groupadd -g 3100 webdev, adds each developer with usermod -aG webdev, and assigns the web root with chgrp -R webdev /var/www.
She then sets the directories to mode 2775 so that new files inherit the webdev group and remain editable by the whole team. Because a second server mounts the same content over NFS, she creates the group there with the same GID of 3100. Each developer now signs in with a personal account, the logs show individual accountability, and access is revoked simply by removing a person from the group.