The groupadd Linux Command

Create new Linux user groups to better manage permissions

Lunch Time In The Office.
vgajic / Getty Images

The groupadd command creates a new group account using the values specified on the command line and the default values from the system. The new group will be entered into the system files as needed. This is one of the simpler commands you'll encounter, and it gets straight to the point. Because groupadd is a system command, you're going to need to pair it with sudo or run it as the root user.

sudo groupadd -g 1010 lifewire

The above command creates a new group, "lifewire," with a group ID of 1010.

Linux groupadd command

That's about all there is to it, most of the time. Like with any command, there are more options available, should you need them. The options which apply to the groupadd command are:

-g gid

The numerical value of the group's ID. This value must be unique unless the -o option is used. The value must be non-negative. The default is to use the smallest ID value greater than 500 and greater than every other group. Values between 0 and 499 are typically reserved for system accounts.

-r

This flag instructs groupadd to add a system account. The first available gid lower than 499 will be automatically selected unless the -g option is also given on the command line. This is an option added by Red Hat.

-f

This is the force flag. This will cause groupadd to exit with an error when the group about to be added already exists on the system. If that is the case, the group won't be altered (or added again). This option also modifies the way -g option works. When you request a gid that it is not unique and you don't specify the -o option too, the group creation will fall back to the standard behavior (adding a group as if neither -g or -o options were specified). This is an option added by Red Hat.

You may also want to check out the useradd(8) command.

Use the man command (% man) to see how a command is used on your particular computer.