/**/ How to use groupadd command in Linux? - Dextutor

How to use groupadd command in Linux?


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.


                groupadd [Options] group


                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.

After groupadd command in linux
After groupadd command in linux

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.

After -g option with groupadd

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)

After -r option with groupadd
After -r option with groupadd

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.

Before -o option with groupadd
Before -o option with groupadd

The group Ubuntu has the GID 2025. Now, we will create another group Redhat with the same GID.

Using -o option with groupadd command in linux
Using -o option with groupadd

The contents of /etc/group shows that now two groups Ubuntu and Redhat have the same GID.

After -o option with groupadd command in linux
After -o option with groupadd

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?

Leave a Comment