Add New Groups in Ubuntu
Need to create a new group? Here's how to create groups in Ubuntu using the groupadd command.
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_groupnameI 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
To use any command, it is necessary to know its syntax. So here's the syntax for the groupadd command:
sudo groupadd [OPTIONS] GROUPNAMEThe syntax is pretty simple!
So if I want to create a new group named LU, I'd be using the following command:
sudo groupadd LUOnce 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'
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 GROUPNAMESo 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 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
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 sysgroupSo let's say I want to create a system group named system, then I will be using the following command:
sudo groupadd -r system
What next?
Now that you have created a new group, perhaps you should also learn about adding a user to the group:

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

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

