Users

The groupadd command

Creates a new group to share file permissions among several users.

Syntax

sudo groupadd [opciones] grupoTry it in the terminal →

Most useful options

-g, --gid <gid>Sets the group number. It must be unique unless you add -o
-r, --systemCreates a system group, with a number from the system group range in /etc/login.defs
-f, --forceIf the group already exists, it exits successfully and does nothing. With -g, if the GID already exists it picks another one
-o, --non-uniqueAllows a GID that another group already uses
-U, --users <usuarios>Adds those users as members, separated by commas and without spaces. Only in recent versions of shadow

Copy-ready examples

$ sudo groupadd equipo && getent group equipocreates the group and checks that it exists.

Example output

equipo:x:1001:
$ sudo groupadd -g 2000 proyectocreates the group with a fixed number, useful when another machine or a mounted disk must match.
$ sudo groupadd -U alumno,profe aulacreates the group and adds both users from the start.
$ sudo groupadd -f sudodoes not fail if the group already exists. Useful in scripts that run more than once.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
groupadd: group 'equipo' already existsA group with that name already exists in the system.Look at the group with getent group equipo. If you only need it to exist, add -f.
groupadd: 'Mi equipo' is not a valid group nameThe name contains a space. Only letters, digits, underscores and dashes are allowed; it cannot start with a dash or be all digits.Use a name without spaces, for example mi_equipo.
groupadd: GID '2000' already existsThat number is already used by another group.Pick another GID. Use -o only if you really need two groups with the same number.

Typical mistakes

  • It needs administrator rights. Without sudo, the system will not let you create the group.
  • If the name already exists in NIS or LDAP, groupadd rejects it even if it does not appear in /etc/group.
  • Creating a group adds nobody: members are assigned with -U or with usermod -aG.

Differences from similar commands

  • groupdel: deletes a group and removes its entries from the system. groupadd only creates it.
  • usermod: adds a user to a group that already exists with -aG. Creating the group and assigning members are separate steps.
  • getent: checks whether the group exists and which number it has, without changing anything.

FAQ

How is the group number chosen?

Without -g, the system takes the next free number from GID_MIN in /etc/login.defs, which is 1000 by default. With -r, it uses the system group range.

When should I use -r?

For service groups, not for people. Their numbers come from the system range, which by default sits below 1000.

How do I check that the group was created correctly?

With getent group name. If the line appears, it exists; the last field lists the members.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course