Adding Groups

Adding new groups with groupadd

The groupadd command is used by a Systems Administrator to create new groups. The following options are available to the Linux groupadd command.

Groupadd command options

Below are the options that can be used by the "groupadd" command.

Usage: groupadd [options] GROUP

  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       directory prefix
      --extrausers              Use the extra users database

Adding a group - groupadd

In its simplest from the "groupadd" command takes the syntax of:

groupadd group

By issuing the "groupadd" command followed by the name of a group you would like to create, you will create a group with the next available GID. A group identifier, often abbreviated to GID, is a numeric value used to represent a specific group on Linux system.

[root@fedsrv01a ~]# groupadd devops

[root@fedsrv01a ~]# grep devops /etc/group

In the above example, the group "devops" was created. The system used the next available GID "1011".

Adding a group and specifying a GID

By using the "-g" or "--gid" option we can specify that when a group is created it should use the specified GID.

groupadd -g GID group

[root@fedsrv01a ~]# groupadd -g 1020 operators

[root@fedsrv01a ~]# grep operators /etc/group

In the above example, the group "operators" was created with a user specified GID of "1020".