Use
groupadd command in linux is used to create a new group with values specified on command line plus the default values mentioned in the system.
Synopsis
groupadd [Options] group
Example
The list of existing groups in the system is available in /etc/group file. We create a new group named Centos and check the entry in this file.
The Centos group is created with a default GID 1009.
Options available with groupadd command in linux
1. To assign GID of choice
-g : options assigns a GID of user’s choice to the newly created group. The mentioned GID must be free to use i.e., no exiting group should have that GID.
For Example: We create a new group Ubuntu having GID 2025.
2. Overriding /etc/login.defs default values
-K : option overrides the default values (such as GID_MIN, GID_MAX) specified in the /etc/login.defs file.
3. Create a system group
-r : option creates a group with GID from SYS_GID_MIN-SYS_GID_MAX (check the values in /etc/login.defs file)
4. Create groups with same GID
-o : option allows you to create a group with non-unique GID i.e., there will be multiple groups with the same GID.
The group Ubuntu has the GID 2025. Now, we will create another group Redhat with the same GID.
The contents of /etc/group shows that now two groups Ubuntu and Redhat have the same GID.
PPT on groupadd command
Video on groupadd command
Other useful commands in Linux
Some helpful questions
Q1. Write the command to create a group named Cars whose GID is 3030.
Q2. Which file contains the information related to the existing groups in the system?
Q3. What is the difference between a normal group and a system group?