Create new group in Ubuntu
How To

Add New Groups in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

Want to know how you can add new groups in Ubuntu? You just have to use this command as root or sudo user:

groupadd new_groupname

I encountered this issue when I was installing Docker on Ubuntu. To run Docker without sudo all the time, you have to create a new group named docker and add the user to this new group.

Don't worry. I will show you how to use the groupadd command to create new groups in Ubuntu in detail. I'll also show how to create new groups with specific group IDs.

Adding new groups using the groupadd command

🚧
Only the root or the user with superuser privileges can create a new group.

To use any command, it is necessary to know its syntax. So here's the syntax for the groupadd command:

sudo groupadd [OPTIONS] GROUPNAME

The syntax is pretty simple!

So if I want to create a new group named LU, I'd be using the following command:

sudo groupadd LU

Once done, you list all the groups by listing the file contents of the /etc/group file. And to sort the output, here, I have used the less command with the grep:

less /etc/group | grep -w 'Group-name'
list all the groups and use the grep command to sort the output

That's neat. Let's see some complex and advanced usage.

Create a new group with a specific group ID

In Linux, the group is identified by the group ID so if you are running a main frame system having various groups, creating a group with a specific group ID can be a good idea.

To do so, you'd have to use the groupadd command with the -g flag as shown below:

sudo groupadd -g Group-ID GROUPNAME

So let's say I want to create a new group named hello having the GID of 786, then I will be using the following command:

sudo groupadd -g 786 hello
create a group with the specific group id in ubuntu

Create a new group within the specific GID range

By default, the groups will be created by the range specified in the /etc/login.defs file.

But you can use the -K flag followed by the GID_MIN and GID_MAX to specify the desired range.

Sounds confusing? Here's the syntax:

groupadd -K GID_MIN=[value] -K GID_MAX=[value] [GROUPNAME]

So let's say I want to create a new group and its GID must range from 2000 to 2100, then I'd have to use the following:

sudo groupadd -K GID_MIN=2000 -K GID_MAX=2100 NewRange
Create a new group within the specific GID range

And as you can see, the group NewRange was given the GID 2000!

Create a system group in Ubuntu

The system groups are special groups that are used to perform system-wide operations like creating backups and are low in the GID.

To create a system group, you'd have to use the -r flag with the groupadd command:

sudo groupadd -r sysgroup

So let's say I want to create a system group named system, then I will be using the following command:

sudo groupadd -r system
create a system group using the groupadd command

What next?

Now that you have created a new group, perhaps you should also learn about adding a user to the group:

How to Add User to a Group in Ubuntu Command Line
Here’s how you can assign a new group to an existing user or change its primary user group in Ubuntu. Also learn about creating new users with given groups.

And here are some commands you should know about group management in Linux.

5 Commands for Group Management in Linux
Group is an essential part of Linux system management and security. Check out various commands that you can use for managing groups in Linux.

I hope you will find this helpful. And if you have any suggestions, leave a comment.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.