Skip to content

Linux groupadd command

The Linux groupadd command is used to create a new group on a Linux system. This command allows system administrators to easily manage user groups. By using the groupadd command, you can specify group names, GID (Group ID), and other options to customize the group creation process. Groupadd is a powerful tool that helps organize users into logical groups for easier management of permissions and access control on a Linux system.

groupadd Syntax:

Terminal window
groupadd [options] group_name

Options:

OptionDescription
-g, —gid GIDSpecify the numerical GID for the new group
-K, —key KEY=VALUEOverrides /etc/login.defs defaults
-o, —non-uniqueAllow using a non-unique GID for the group
-p, —password PASSWORDSet the encrypted password for the new group

Parameters:

ParameterDescription
group_nameThe name of the group to be created

groupadd Usage:

Create a New Group

Terminal window
groupadd developers

Creates a new group named “developers”.

Specify GID when Creating a Group

Terminal window
groupadd -g 1001 testgroup

Creates a new group named “testgroup” with GID (group ID) 1001.

Create a Group with Specific System ID

Terminal window
groupadd -r sysadmin

Creates a system group “sysadmin” with a GID less than 1000, primarily used for system users.

Create a Group with Comments

Terminal window
groupadd -g 2002 -c "Finance Group" finance

Creates a new group named “finance” with GID 2002 and comments as “Finance Group”.

Common Questions on groupadd Usage:

How do I use groupadd in Linux?

To use the groupadd command in Linux, execute the following command:

Terminal window
groupadd newgroup

What options can I use with groupadd in Linux?

To see the available options that can be used with the groupadd command in Linux, you can refer to the man pages by running:

Terminal window
man groupadd

How can I specify a GID (Group ID) when creating a group using groupadd in Linux?

You can specify a GID for a new group by providing the —gid option followed by the desired GID number when using the groupadd command. For example:

Terminal window
groupadd --gid 1001 newgroup

How can I specify additional supplementary group IDs for a new group in Linux using groupadd?

To specify supplementary group IDs for a new group in Linux, you can use the —group option followed by a comma-separated list of GID numbers. Here is an example:

Terminal window
groupadd --group 1001,1002 newgroup

How can I create a system group using the groupadd command in Linux?

To create a system group (a group with a GID less than or equal to 999) in Linux with groupadd, you can use the —system option. Here is an example:

Terminal window
groupadd --system sysgroup

How can I prevent groupadd from creating a group if it already exists in Linux?

To prevent groupadd from creating a group if it already exists, you can use the -k or —non-unique option with the command. This will prevent the creation of a group with a duplicate name. Example:

Terminal window
groupadd -k existinggroup

Can I set a specific password for a newly created group using the groupadd command in Linux?

No, the groupadd command does not directly allow setting a password for a group during creation. Group passwords are typically managed through the /etc/group file or other group management tools available in Linux.

Terminal window

Applications of the groupadd command

  • Create a new group on the system
  • Specify the GID (Group ID) for the new group
  • Define the group password
  • Assign specific group ownership to files and directories