Create a group in Ubuntu

Published: October 07, 2022

Create a group in Ubuntu

Grouping users is one of the method, which helps us limit users' access to files, directories, peripherals etc. Users, if part of the same group, get access to all the mentioned resources. This for sure, is not the way forward. Certainly, we want to ensure that only those users have access to resources that they are meant to.

Consider a scenario wherein we have two users working on a project. And, we want to ensure that they can't access project files of the other. Then, it would be great to put them in two different groups.

Here, we cover how to create a group in Ubuntu through addgroup command-line utility.

Note: Following operations require superuser privileges. In case you don't have one then, we advise you to contact your System Administrator for assistance.

Create a group in Ubuntu

Open a terminal and issue the following -

sudo addgroup <group_name>

This creates a group <group_name>, with a Group ID. The Group ID would be shown during the process. Alternately, we can view Group ID through -

cat /etc/group | grep <group_name>

Besides, what if we want to assign a specific Group ID to our group. Then, we should know that -

Group ID (0) is assigned to root group,

Group ID's (1-999) are assigned to system groups and,

Group ID's (1000 and above) are for regular groups.

So, from here we know that if we want to assign Group ID to a regular group of our choice then it should be above 1000 and shouldn't already have been assigned to another group. Use the following syntax -

sudo addgroup --gid <GROUPID> <user_name>

It is worth mentioning here that, the moment we create a user account, system by default creates a primary group with same name as that of user.

In conclusion, we have covered how to create a group in Ubuntu using addgroup command-line utility.