The groupadd command creates a group. By default, the group has no members and no password. In addition to creating a group with a friendly name, you can also specify a group ID using the -g option.
Some groupadd options include the following.
Option | Description |
---|---|
-g | Assign a group ID. |
-f | Exit with a success status if the group already exists. |
-o | Allow a group to be created with a non-unique group ID. |
The groupadd command allows you to add groups to the system from the command line. To do so, log in as the root user and enter the following command:
# groupadd groupname
where groupname is the name of the group you want to add to the system. For example, to add the group www to your system, you would use the command:
# groupadd www
If you encounter below error while running the groupadd command:
groupadd: command not found
you may try installing the passwd package as shown below as per your choice of distribution.
Distribution | Command |
---|---|
Debian | apt-get install passwd |
Ubuntu | apt-get install passwd |
Alpine | apk add shadow |
Arch Linux | pacman -S shadow |
Kali Linux | apt-get install passwd |
Fedora | dnf install shadow-utils-2 |
Raspbian | apt-get install passwd |
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
Conclusion
The groupadd command can be used with multiple options to create a supplementary group for user accounts, or a system user group. See the man page regarding groupadd for a full list of all the command-line options available.