Home > Package & System Management > groupadd

groupadd: Create a New Group

groupadd is a command used to create new user groups on a Linux system. It allows you to add new groups to the system, specify a Group ID (GID) if needed, or designate it as a system group. It's commonly used to pre-create relevant groups before creating user accounts.

Overview

groupadd is used to create new groups on a Linux system. Created groups are recorded in the `/etc/group` file and can be assigned to user accounts. When creating a group, you can explicitly specify the GID (Group ID) along with the group name, or let the system automatically assign one.

Key Features

  • Create new user groups
  • Specify a particular Group ID (GID)
  • Create as a system group (assign low GID)
  • Check and handle duplicate group names

Key Options

The groupadd command provides various options to configure group creation.

Group Settings

Generated command:

Try combining the commands.

Description:

`groupadd` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn how to create groups through various examples of using the groupadd command.

Create a Basic Group

sudo groupadd developers

In its most basic form, this creates a new group named 'developers'. The GID is automatically assigned by the system.

Create a Group with a Specific GID

sudo groupadd -g 1005 sales

This creates a group named 'sales' with GID 1005. An error will occur if GID 1005 is already in use.

Create a System Group

sudo groupadd -r web_services

This creates a system group named 'web_services'. This group is typically assigned a GID from the lower range.

Verify Group Creation

getent group developers

Check the information of the created group. You can verify it directly in the `/etc/group` file or use the `getent group` command.

Tips & Precautions

Points to note and useful tips when using the groupadd command.

Permissions

The groupadd command modifies system settings, so it can only be executed by the root user or a user with sudo privileges.

  • Always use it with `sudo` or run as the root user.

GID Range

The GID ranges for regular user groups and system groups may vary by distribution, but generally follow this pattern:

  • **Regular User Groups**: 1000 and above (most Linux distributions)
  • **System Groups**: 1-999 (for system services)

Group Names

Group names must be unique within the system, and it's advisable to follow certain conventions.

  • Group names typically consist of lowercase English letters, numbers, hyphens (-), or underscores (_).
  • Group names can be up to 32 characters long.

Related Commands

Other useful commands for group management:

  • `groupdel`: Delete an existing group
  • `groupmod`: Modify an existing group (change name, GID, etc.)
  • `gpasswd`: Set group passwords and manage group members
  • `useradd`: Specify a primary group or include in supplementary groups when creating a user

Same category commands