Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Permissions and Users

Linux groupadd command

Reference for the Linux groupadd command: create a group, choose its GID, make system groups, and add members with usermod, gpasswd or groupmod.

groupadd creates a new group by adding a line to /etc/group (and /etc/gshadow). A group is a name plus a numeric ID (GID); users that belong to it share the permissions granted to that group on files and directories. Groups are the standard way to give a team access to a shared folder without making the files world-writable.

The command only creates the group; it adds no members. Use usermod -aG or gpasswd -a afterwards, and set the group on a directory with chgrp and a setgid bit so new files inherit it.

Terminal
sudo groupadd developers

Try it

Creating groups needs root; these examples read the group database and build a shared-folder layout in your own directory.

Bash Reading the group database

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Shared folder with setgid

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
groupadd [OPTION]... GROUP
Option Description
-g GID, --gid GID Use this numeric ID (must be unique unless -o is also given).
-o, --non-unique Allow a GID that is already in use.
-r, --system Create a system group with a GID from the system range (below 1000 on most systems).
-f, --force Exit successfully if the group already exists; with -g, choose another GID if the given one is taken.
-K KEY=VALUE Override defaults from /etc/login.defs (such as GID_MIN).
-p HASH Set an encrypted group password (rarely used).

Returns: 0 on success; 9 if the name is already in use; 4 if the GID is already in use; 3 for an invalid argument.

Usage notes

  • Group names follow the same rules as user names: start with a letter or underscore, lowercase letters and digits, up to 32 characters.
  • Pick GIDs consistently. If several servers share files over NFS, use the same numeric GID everywhere, so file ownership matches.
  • Idempotent scripts: groupadd -f developers does not fail when the group exists, so a setup script can run twice safely.
  • System groups (-r) are for services; they live below GID_MIN and should have no regular users.
  • Changes need a new login before a running shell sees them as one of its groups; see newgrp.
  • Rename and delete with groupmod -n and groupdel. A group cannot be deleted while it is some user's primary group.
  • Debian's addgroup is a wrapper with friendlier messages; groupadd is portable.
  • Directory sharing recipe: groupadd team, usermod -aG team alice, chgrp team /srv/team, chmod 2775 /srv/team. The leading 2 is the setgid bit.