Linux groupadd command
The groupadd
command in Linux is used to create new groups on the system. Groups in Linux allow you to assign and manage permissions for collections of users, making it easier to control access to files and resources.
1. Basic Syntax of groupadd
The basic syntax of groupadd
is:
This command creates a new group with the specified name.
2. Examples of groupadd
with Expected Output
Example 1: Creating a New Group
Command:
Expected Output:
When you successfully create a group with groupadd
, there’s typically no output unless there is an error. To verify the group creation, you can check /etc/group
or use getent group
:
Expected Output:
Here, 1001
is the Group ID (GID) assigned to developers
. Linux automatically assigns a unique GID, but you can specify one if needed.
Example 2: Creating a Group with a Specific GID
Command:
Expected Output:
In this example, groupadd
creates a group named testers
with the GID 1050. If the GID 1050 is already taken by another group, you’ll see an error:
Example 3: Creating a System Group
System groups are typically used for system processes and have lower GIDs (generally below 1000). To create a system group, use the -r
option.
Command:
Expected Output:
To check if the group was created as a system group, view its GID, which will usually be below 1000:
Expected Output:
3. Error Messages from groupadd
Duplicate Group Name:
Output:
This error occurs if you try to create a group with a name that already exists in the system.
Invalid GID:
Output:
The GID must be a positive integer. Negative or invalid numbers will trigger this error.
4. Verifying Group Creation
To confirm a group was created successfully, you can use:
For example:
Expected Output:
Summary of groupadd
Options
- -g <GID>: Specifies a GID for the group.
- -r: Creates a system group with a lower GID, typically below 1000.
The groupadd
command is a straightforward utility for managing group creation on Linux systems. By understanding its output and verifying group creation, administrators can effectively manage group-based permissions on Linux.