addgroup
Quick Reference
Command Name:
addgroup
Category:
user management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
User group creation
Create new user groups for organizing system users
- 2
Permission management
Set up groups for managing file and directory access permissions
- 3
System administration
Organize users into logical groups for easier management
- 4
Multi-user environments
Create groups for shared access to resources and files
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 groupsudo addgroup developers# Create a new system group
sudo addgroup --system sysgroup# Create a group with a specific GID
sudo addgroup --gid 1001 developers# Add an existing user to a group
sudo addgroup johndoe developers# Create a group with a specific name
sudo addgroup --group developers
Advanced Examples:
# Create a group with a specific GID and add a usersudo addgroup --gid 1001 --ingroup developers johndoe# Create a system group with a specific GID
sudo addgroup --system --gid 999 servicegroup# Create a group and add multiple users
sudo addgroup developers && sudo adduser johndoe developers && sudo adduser janedoe developers# Create a group with a specific name and GID
sudo addgroup --group --gid 1001 developers# Create a group and set it as the primary group for a user
sudo addgroup --group developers && sudo adduser --ingroup developers johndoe
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 messagesaddgroup
has integration with the system's configuration via/etc/adduser.conf
addgroup
is more distribution-specific, whilegroupadd
is available on all Linux distributionsaddgroup
can also be used to add a user to a group (identical toadduser user group
)
Dual Purpose Command:
The addgroup
command can be used in two different ways:
- To create a new group:
addgroup groupname
- 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
toLAST_SYSTEM_GID
- For regular groups, a GID is chosen from the range defined by
FIRST_GID
toLAST_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
orgroupdel
command
Common Use Cases
User group creation
Create new user groups for organizing system users
Permission management
Set up groups for managing file and directory access permissions
System administration
Organize users into logical groups for easier management
Multi-user environments
Create groups for shared access to resources and files
Security organization
Group users by security clearance or access requirements
Related Commands
Use Cases
User group creation
Create new user groups for organizing system users
Permission management
Set up groups for managing file and directory access permissions
System administration
Organize users into logical groups for easier management
Multi-user environments
Create groups for shared access to resources and files
Security organization
Group users by security clearance or access requirements
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.