addgroup

user managementlinux
The addgroup command is one of the most frequently used commands in Linux/Unix-like operating systems. addgroup The addgroup command creates a new group on the system. It is a more user-friendly alternative to the lower-level groupadd command, and is commonly used on Debian-based Linux distributions like Ubuntu.

Quick Reference

Command Name:

addgroup

Category:

user management

Platform:

linux

Basic Usage:

addgroup [options] [arguments]

Common Use Cases

    Syntax

    addgroup [options] [--gid ID] [--system] [--group] group

    Options

    Option Description
    --system Create a system group (low GID)
    --gid ID Use ID for the group ID instead of automatic selection
    --firstgid ID Use ID as the smallest GID when automatically selecting
    --lastgid ID Use ID as the largest GID when automatically selecting
    --group Selects the group creation mode
    --force-badname Allows group names that don't conform to the strict policy
    --quiet Suppress informational messages, only show warnings and errors
    --debug Be verbose when processing and show debugging information
    --conf FILE Use FILE instead of the default configuration file
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the addgroup command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Create a new group with default settings
    addgroup developers
    # Create a new system group addgroup --system sysgroup
    # Create a group with a specific GID addgroup --gid 1500 webadmin
    # Add a user to an existing group (same as adduser) addgroup john developers

    Advanced Examples:

    # Create a system group with a specific GID
    addgroup --system --gid 850 daemons
    # Create a group with force mode (disables duplicate check) addgroup --force-badname custom-group-name
    # Create a group with verbose output addgroup --debug developers # Add a user to a group using the alternate syntax addgroup john sudo # Create a group within a specific GID range addgroup --firstgid 1000 --lastgid 2000 project-team

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Addgroup vs Groupadd:

    The addgroup command is a Debian/Ubuntu-specific script that provides a more user-friendly interface to the lower-level groupadd command. Key differences include:

    • addgroup provides more informative output and better error messages
    • addgroup has integration with the system's configuration via /etc/adduser.conf
    • addgroup is more distribution-specific, while groupadd is available on all Linux distributions
    • addgroup can also be used to add a user to a group (identical to adduser user group)

    Dual Purpose Command:

    The addgroup command can be used in two different ways:

    1. To create a new group: addgroup groupname
    2. To add a user to an existing group: addgroup username groupname

    When two arguments are provided, addgroup assumes you want to add the first argument (user) to the second argument (group).

    Group Types:

    There are two main types of groups you can create:

    • Regular groups: Used for organizing users and permissions, typically with GIDs of 1000+
    • System groups: Used by system services and daemons, typically with GIDs below 1000

    Configuration:

    The addgroup command is configured through the /etc/adduser.conf file, which defines default settings such as:

    • GID ranges (FIRST_GID, LAST_GID)
    • System group GID ranges (FIRST_SYSTEM_GID, LAST_SYSTEM_GID)

    Group Naming:

    By default, group names must follow these rules:

    • Begin with a lowercase letter or underscore
    • Contain only lowercase letters, digits, underscores, or dashes
    • Not exceed 32 characters in length

    The --force-badname option allows you to create groups with names that don't conform to these rules, but this may cause compatibility issues with some software.

    GID Assignment:

    When creating a group, the GID (Group ID) is assigned as follows:

    • If --gid is specified, that GID is used (if available)
    • For system groups, a GID is chosen from the range defined by FIRST_SYSTEM_GID to LAST_SYSTEM_GID
    • For regular groups, a GID is chosen from the range defined by FIRST_GID to LAST_GID

    Important Notes:

    • The addgroup command requires root privileges (sudo)
    • Changes to group settings are stored in /etc/group and /etc/gshadow
    • Creating a group with the same name as an existing group will result in an error
    • System groups are typically used for daemons, services, and system applications
    • To modify an existing group, use the groupmod command
    • To delete a group, use the delgroup or groupdel command

    Related Commands

    These commands are frequently used alongside addgroup or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the addgroup command works in different scenarios.

    $ addgroup
    View All Commands