Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux groupadd Command: Add User Group

The groupadd command is a Linux command-line utility used to create new groups in the system. In this tutorial, we'll go over the basics of the groupadd command and its usage.

  • Basic Syntax

The basic syntax for the groupadd command is:

groupadd [options] group_name
  • Common Options

Here are some common options used with the groupadd command:

  • -g: Specify the Group ID (GID) for the new group.
  • -r: Create a system group with a GID less than 1000.
  • -K: Overwrite the default value for specified key (e.g., GROUP_ADD_CMD).
  • Examples

Here are some examples to illustrate the usage of the groupadd command:

  • Create a new group named developers:
sudo groupadd developers
  • Create a new group with a specific GID:
sudo groupadd -g 1500 developers
  • Create a new system group:
sudo groupadd -r sysgroup
  • Create a group and override the default group creation value:
sudo groupadd -K GID_MIN=500 -K GID_MAX=2000 customgroup
  • Verify Group Creation

To verify that the group was created successfully, you can check the /etc/group file, which contains a list of all groups in the system:

grep 'group_name' /etc/group

Replace group_name with the name of the group you created.

In summary, the groupadd command is a useful utility for creating new groups in Linux. It allows you to create system and non-system groups and specify the GID when needed. Make sure to run the command as root or with sudo to have the necessary privileges.

  1. How to use the groupadd command in Linux:

    • Description: groupadd is a command-line utility in Linux used to create new user groups.
    • Example:
      sudo groupadd groupname
      
  2. Adding user groups with groupadd:

    • Description: Use groupadd to add a new user group to the system.
    • Example:
      sudo groupadd mygroup
      
  3. Creating new groups in Linux using groupadd:

    • Description: groupadd is used to create new groups on the system.
    • Example:
      sudo groupadd newgroup
      
  4. Setting group ID and additional options with groupadd:

    • Description: Specify additional options when creating a group, such as the group ID (GID), using the -g option.
    • Example:
      sudo groupadd -g 1001 mygroup
      
  5. Checking existing groups before using groupadd:

    • Description: Verify if a group already exists using the grep command along with /etc/group.
    • Example:
      grep mygroup /etc/group
      
  6. Adding users to newly created groups with groupadd:

    • Description: After creating a group, use the usermod command to add users to it.
    • Example:
      sudo usermod -aG mygroup username
      
  7. Viewing group information in Linux after using groupadd:

    • Description: Use the getent command to view information about a specific group.
    • Example:
      getent group mygroup