The groupadd command creates a group. By default, the group has no members and no passwords. In addition to creating a group with a friendly name, you can also specify a group ID using the -g option.
Below are associated configuration files:
- /etc/group: Group account information.
- /etc/gshadow: Secure group account info.
- /etc/login.defs: Shadow password suite configuration.
Syntax
The syntax of the groupadd command is:
# groupadd [options] {group names}
Some groupadd options include the below.
Option | Used To | Example |
---|---|---|
-f | Assign a group ID. | # groupadd -g 123 sales |
-f | Exit with success if group already exists | # groupadd -f sales |
-o | Allow group creation with non-unique ID | # groupadd -o -g 123 sales |
groupadd Command Examples
1. To create a new group:
# groupadd SUPPORT
2. To show success status if the group already exists:
# groupadd -f SUPPORT # groupadd --force SUPPORT
3. To specify the numerical group ID:
# groupadd -g 504 SUPPORT # groupadd --gid 504 SUPPORT
4. To get the help info:
# groupadd -h # groupadd --help
5. To specify the “/etc/login.defs” values:
# groupadd -K KEY=VALUE # groupadd --key KEY=VALUE # groupadd -K GID_MIN=100 # groupadd -K GID_MAX=499
6. To add a group with non-unique vale:
# groupadd -o 500 SUPPORT # groupadd --non-unique 500 SUPPORT
7. To specify the encrypted password for group:
# groupadd --password !$424733244%^12124 SUPPORT
8. To create a system group:
# groupadd -r 499 SUPPORT