Ubuntu create group

A command used to create a group in Ubuntu is groupadd. It is a simple command. Here is an information about groupadd from the manual page:

NAME
groupadd - create a new group

SYNOPSIS
groupadd [-g GID [-o]] [-f] [-K KEY=VALUE] group

DESCRIPTION
The groupadd command creates a new group account using the values
specified on the command line plus the default values from the system.
The new group will be entered into the system files as needed.
The options in synopsis means:
  • -g GID means we can provide a group id to the new group. However the group id must be greater than 999 and hasn't been used by existing group.
  • -o permits to add a group with a non-unique GID.
  • -f will turn off -g group id you specified if it's already been used by the existing group. If the name of the new group you specified already exist, it will exit with success status.
  • -K KEY=VALUE overrides /etc/login.defs defaults (GID_MIN, GID_MAX and others).
The groupadd command can be used with no option. So, the format to create a new group can be as simple as:

groupadd new_group_name

Here is an example of Ubuntu create group using groupadd command:

luzar@ubuntu:~$ sudo groupadd itdept
[sudo] password for luzar:
luzar@ubuntu:~$
All Ubuntu groups were kept in one file. The location of the file is in /etc/group. We can view groups in Ubuntu using cat, less, more or text editor. Here is an example of Ubuntu /etc/group file:
luzar@ubuntu:~$ sudo less /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
...
...
...
jimi:x:1002:
alex:x:1003:
itdept:x:1004:
See the itdept group that we created just now? We didn't specify a gid, so Ubuntu assigns a next gid from the existing groups.