<span>groupadd</span> is the command used in Linux systems to create new user groups. It is typically used by system administrators when managing user permissions or controlling resource access.
🔧 Basic Syntax
groupadd [options] group_name
✅ Common Options
| Option | Description |
|---|---|
<span>-g GID</span> |
Specifies the GID (Group ID) for the group, which must be a unique and unused number. |
<span>-r</span> |
Creates a system group (GID is usually less than 1000, depending on the distribution). |
<span>-f</span>, <span>--force</span> |
If the group already exists, no error will be reported, and its properties may be modified (when used with <span>-g</span>, a non-conflicting GID will be automatically assigned). |
<span>-o</span>, <span>--non-unique</span> |
Allows the creation of a group with a non-unique GID (i.e., GID can be duplicated, generally not recommended). |
📌 Examples
-
Create a regular user group
sudo groupadd developersCreates a user group named
<span>developers</span>, with the GID assigned automatically by the system. -
Create a group with a specified GID
sudo groupadd -g 1001 testersCreates a group named
<span>testers</span>with a GID of 1001. -
Create a system group
sudo groupadd -r nginxCreates a system group named
<span>nginx</span>, suitable for service accounts, with a GID within the system reserved range. -
Force creation (no error if the group exists)
sudo groupadd -f tempgroupIf
<span>tempgroup</span>already exists, the command still exits successfully. -
Allow non-unique GID (rarely used)
sudo groupadd -g 1000 -o duplicate_groupAllows creation even if GID 1000 is already used by another group.
🗂️ Related Files
-
<span>/etc/group</span>: Stores all user group information, formatted as follows:group_name:x:GID:user_listFor example:
developers:x:1001:alice,bob -
<span>/etc/gshadow</span>: Contains encrypted information and administrator settings for the group (e.g., using<span>gpasswd</span>to set a group password).
⚠️ Notes
- Root permissions are required to execute
<span>groupadd</span>. - GIDs should avoid conflicts; do not use
<span>-o</span>unless necessary. - After creating a group, use
<span>usermod</span>or<span>gpasswd</span>to add users to the group:sudo usermod -aG developers alice
🔄 Similar Commands
| Command | Function |
|---|---|
<span>groupdel</span> |
Deletes a user group |
<span>groupmod</span> |
Modifies an existing user group (e.g., changes GID or group name) |
<span>groups</span> |
Displays the groups a user belongs to |
<span>id</span> |
Shows user and group information (e.g., <span>id username</span>) |