Linux online course

Create Groups in Linux with addgroup

Learn how to create Linux groups with addgroup, assign a GID, add existing users, verify memberships, and use groupadd when needed.

Linux groups organize user accounts so that permissions and access rules can apply to several users at once. For example, a group named developers can be given access to project files without granting that access individually to every user.

A group has both a readable group name and a numeric GID, or Group ID. Linux uses the GID internally, while administrators usually work with the name. The name and GID must identify one group uniquely within the relevant account database.

Group-related concepts

TermMeaningWhy it matters
Group nameThe human-readable name of a group.Commands and administrators commonly use it to refer to the group.
GIDThe numeric identifier Linux uses internally for a group.It must not conflict with another group, especially when sharing files or account data between systems.
Primary groupThe main group associated with a user account.It is generally the default group for files the user creates.
Supplementary groupAn additional group membership beyond the user's primary group.It grants extra access without changing the user's primary group.
Local group databaseOn traditional systems, local group records are stored in /etc/group.Tools such as getent can resolve groups through the system's configured account sources.

Create a group with addgroup

addgroup is a user-friendly, distribution-provided command for creating groups. On systems that provide it, the basic structure is:

sudo addgroup GROUP_NAME

The group name is required. For example:

sudo addgroup test_group

This creates a group named test_group. Because no GID is supplied, the system selects the next available appropriate GID according to its local account-management rules.

Creating the group does not automatically place ordinary users into it. The group exists first; user membership must be added separately.

Assign a specific GID

Use the --gid option when a particular numeric group ID is required:

sudo addgroup --gid 2000 test_group

This requests GID 2000 for test_group. Choose a GID that is unused and follows the conventions of the local system. If the requested GID already belongs to another group, creation fails rather than creating an ambiguous identity.

Omitting --gid is usually simpler because the system chooses an available value automatically. An explicit GID can be useful when coordinating permissions across systems or matching existing account data, but verify the ID first.

Add an existing user to a group

On distributions that support this form of adduser, add an existing account to a group with:

sudo adduser USER_NAME GROUP_NAME

For example:

sudo adduser jowilliams test_group

This adds the existing user jowilliams to test_group as a supplementary group. It does not create a new user and does not normally change the user's primary group.

The user's current login session may not immediately know about the new membership. Ask the user to log out and back in, or otherwise begin a new login session, before testing access to group-protected resources.

Common command patterns

TaskCommand patternResultNotes
Create a group with an automatically selected GIDsudo addgroup GROUP_NAMECreates the named group with a suitable available GID.Example: sudo addgroup test_group
Create a group with a specified GIDsudo addgroup --gid GID_NUMBER GROUP_NAMECreates the group using the requested numeric ID.The option must be supported locally, and the GID must be unused.
Add an existing user to a groupsudo adduser USER_NAME GROUP_NAMEAdds supplementary membership.This does not create a user.
Verify a groupgetent group GROUP_NAMEDisplays the resolved group record.It can consult local or other configured identity sources.
Verify user membershipid USER_NAMEShows the user's UID, primary GID, and group memberships.Look for the expected group in the groups output.
Use groupadd when addgroup is unavailablesudo groupadd --gid GID_NUMBER GROUP_NAMECreates a group with the lower-level utility.Options and behavior should be checked locally.

Verify the result

Use getent group to check that the group exists:

getent group test_group

The output normally includes the group name, GID, and a list of supplementary members separated by commas. The exact output depends on the configured account database.

Then inspect the user's memberships:

id jowilliams

Confirm that test_group appears in the reported groups. If the user was just added, run this check in a new login session when testing access from that session.

addgroup, groupadd, and distribution differences

addgroup is a convenience front end available on some Linux distributions. groupadd is the lower-level group creation utility commonly available through standard account-management tools. They are related, but their option names and behavior are not necessarily interchangeable.

If addgroup is unavailable, consult the local documentation and use the distribution's documented tool. The common alternative is:

sudo groupadd --gid 2000 test_group

Check command availability and supported options with local documentation such as:

man addgroup
man groupadd
man adduser

Troubleshooting

“addgroup: command not found”

The distribution may not install or use the addgroup helper. Use the locally documented group-management command, commonly groupadd, and check its manual page for supported options.

The requested GID is already in use

Another group owns the numeric ID. Omit the explicit GID to allow automatic selection, or choose an unused value. You can inspect a known group with:

getent group GROUP_NAME

The user or group does not exist

A spelling mistake or missing account is a common cause. Check the user and group separately:

id USER_NAME
getent group GROUP_NAME

Correct the name or create the missing account or group before attempting the membership change.

The user still cannot access protected files

First, start a new login session and confirm membership with id USER_NAME. If membership is present, inspect the target file's group ownership and permission bits. Group membership alone does not grant access when the file or directory permissions do not allow the group to use the resource.

Insufficient permission

Group administration normally requires administrative privileges. Use sudo if the account is authorized, or ask an administrator to perform the change.

Quick workflow

  1. Create the group, letting the system select a GID or specifying an unused one.
  2. Add the existing user as a supplementary member.
  3. Start a new login session for the user.
  4. Verify the group with getent group.
  5. Verify the user's memberships with id.

For broader Linux command-line context, see Linux and showing the full path of shell commands.