How to Create a Group in Linux

December 8, 2023 / How-to Guide

If your Linux distribution supports multiple users, it is more convenient to allocate user permissions through groups rather than individual users. By creating groups with designated permissions and subsequently assigning users to these groups, you can extend the group’s permissions to all users within it.

Follow these steps to create a group in Linux.

  1. Log in as the root user using your username and password.
    Note:- Only the main user (root) or a user with special permissions (sudo) can make new groups.
  2. To create a new group, you need to use the groupadd command. The command will appear like this:
    groupadd

    Note: If the new group you’re trying to make already exists, Linux will show an error telling you that the group is already there.

  3. Once the group has been created, the groupadd command will add data to your created group to the files /etc/group and /etc/gshadow.
  4. When creating a new group, your system will automatically add a unique GID, an integer associated with the group, from the next available number on the list. If you’d like to manually specify the GID of your new group, you can do using the command:
    groupadd -g ####

    To select the particular GID linked to the group, replace “####” with a 4-digit integer. For instance, if you wish to make a group named NewGroup2 with a GID of 1073, you can specify it using the command:

    groupadd -g 1073 NewGroup2

    Note: If the GID you picked is already assigned to another group, you’ll receive an error message notifying you of the conflict.

In this way, you can create a group in Linux. For more information on Linux, visit our knowledge base section.

Spread the love