How to Add Groups in Linux: The groupadd Command

Learn how to manage your linux system with the groupadd command to add groups and useradd to add users.

How to Add Groups in Linux: The groupadd Command

This blog post will discuss how to use the groupadd command in Linux. This command adds a new group to the system. Understanding how to use this command to manage your Linux system effectively is important. By the end of the post, you will know how to create groups and add users to the groups you make.

Let's get started!

Sudo Privileges

The first step is to open the terminal. You can do this by pressing Ctrl+Alt+T on your keyboard.
You cannot add a group without sudo privileges. Therefore, you must use the Sudo command to gain access or log in as a root user. To do this, type:

sudo -

Enter your password when prompted.

Once you have access, you can manage your system.

groupadd command

We add groups using the groupadd command, followed by the name of the group you want to add.

The syntax for the command is:

groupadd [options] groupname


If we wanted to add a group called "geekbits", we would type:

groupadd geekbits 

OR: use sudo if not a root user.

sudo groupadd geekbits   

To confirm that the group was added successfully, run this command:

cat /etc/group



As you can see the group "geekbits" was added successfully.

Creating Users : Useradd command

To create a user, we use the useradd command followed by the user's name.

The syntax is as follows:

useradd [username]


sudo useradd grandmaster

Let's confirm the user add was successful.

cat /etc/passwd


postgres:x:113:121:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

Now that the user "grandmaster" was added successfully, Let's see how to add users to groups.

Adding users to a group

New user:

To add a new user to a group, we use the useradd command with -G flag followed by the group's name and then the user's name.

The syntax is as follows:

useradd -G [group name] [username]


sudo useradd -G geekbits jeff



As you can see, the geekbits group has a new user "jeff."

Existing user:

We add existing users to a group using the usermod command.

The syntax is as follows:

usermod -G [group name] [username]


sudo usermod -G geekbits grandmaster

We use the -G option to specify the group to which we want to add the user.



And that's it! You have successfully added a new group to your Linux system (geekbits) and added users (jeff, grandmaster) to the group.

Remember, you can only add groups if you have sudo privileges or be logged in as root. If you need help managing your groups, feel free to contact us for assistance. We're always happy to help!

Thanks for reading:)

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.