Add user to a group in Ubuntu

So, we have already covered how to Change Primary group of a user in Ubuntu. It is necessary for a user to always have a primary group. But, it is not necessary for a user to always be a part of secondary group. If needed, a user can be part of one or more secondary groups.

If there are files, directories or peripherals which are required to be shared between multiple users then, it is better to make them a part of the group. This way we can set group permissions so that only those users who are part of group can read, write or execute.

To Create a group in Ubuntu. A group should exist before we can make a user part of that group.

Here, we will use usermod command-line utility to Add user to a group. This article specifically deals with Secondary groups. If you want to make changes to a users’ primary group then – Change Primary group of a user in Ubuntu.

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

Add user to a group in Ubuntu

Use following syntax, to make user a part of a secondary group –

sudo usermod -aG <group_name> <username>

where, -a is to append, -G is used for secondary groups.

To add user in multiple groups then, separate groups with comma. Don’t put whitespace in between those groups.

sudo usermod -aG <group_n1>,<group_n2>..<group_nN> <username>

For instance, we want user – abc to be a part of group – testgroup. Then,

sudo usermod -aG testgroup abc

If there are multiple groups like testgroup, nxtgroup, firstgroup then –

sudo usermod -aG testgroup,nxtgroup,firstgroup abc

In conclusion, we have covered how to add user to a group in Ubuntu.

Similar Posts