How can you create a Group in Linux

In this Article we will see how to create a group on an Linux RedHat system step by step.

Description of the task

Groups allow system administrators to apply certain permissions or access to groups of users. Groups must be created first before you can assign a user to that group. To add a new group, you will use the groupadd command.

Syntax to create Linux Group

The syntax for the groupadd command is:
groupadd -g Group_ID Group_Name

Parameters or Arguments used with the groupadd command

The groupadd command requires the following two parameters:
-g Group_ID
The -g parameter indicates that a group number will follow. This is the group number that will be assigned to this new group. The group number must be unique.
Group_Name
The name of the group you would like to add. Group names should be entered in lowercase and may contain underscores. It is recommended that you do not use the same group name more than once.

Prerequisites

You need an account with sudo administrative privileges. The sudo command is used to provide the superuser privileges required for the groupadd command.

Create a Group

The following steps will guide you through creating a group on an RedHat Linux system.
  1. To begin adding a new group to your system, you will need to be logged in using a valid user account.In this tutorial, we have logged in as root on one of the AWS EC2 host.
  2. We will add a new group with a Group ID of 9999  and a Group Name of aousers. To add the group called aousers, we would enter the following command:
    sudo groupadd -g 9999 aousers
    The following screenshot demonstrates what you will see.
  3. When you have entered the command, press the Enter key to execute the command.The sudo command will now prompt you to enter the password for your administrator account.Please note that no characters will show as you type your password. This is normal and is important to preserve the security of your password.After you have entered your password, press the Enter key to continue.
  4. If all goes well, you will see the system prompt appear again without any errors. This indicates that the new group called aousers has been added successfully.
In this step we will check to ensure that the group called aousers was added to the system. Since new groups are added to the end of the system group file called /etc/group, we can use the tail command to verify that the new group was added. Enter the following tail command after the system prompt to show the last few lines of the system group file:
sudo tail /etc/group
The following screenshot demonstrates what the command will look like after it is typed. When you have typed the command, press the Enter key to execute the command. As seen in the screenshot below, the following line appears at the end of the /etc/group file indicating that the aousers group was created.
aousers:x:9999:
Great, you have successfully added a new group to your RedHat Linux system!