Add user to a Group in Ubuntu/Linux Mint

For someone who has ever been a system administrator knows how tough it is manage users individually. Sometimes, we need to limit the user’s access as per our team’s requirements. So, to put limits on each of the user can be a time-consuming task. Hence, we manage it efficiently with the help of group feature provided with Ubuntu or related distributions. In this article, we would discuss how to add user to a Group in Ubuntu or Linux Mint.

A bit about Users and Groups

We create groups and add users to it. That means, each of user in the group is allowed to perform certain common tasks. But, they belong to different teams. So, instead of providing unlimited access to all the teams, we pick one user from each team and add them to a group. Then, we assign permissions to each group. Eventually, we are imposing restrictions to other users of team that are not part of a particular group.

This approach provides us the efficient outcome. Hence, we can allocate our limited precious resources to other tasks.

Ubuntu and other related Linux distributions for this approach have User Private Groups. When we create a user then, a new group is also created. The name of our new group is the same as that our of newly created user. Therefore, new user belongs to the same group. For instance, if a new user XYZ is created then, at the same time a new group with XYZ will also be created. And, user XYZ will be allotted the group XYZ.

/etc/group contains the list of groups on a Ubuntu/Linux distribution. To identify which group a user belongs to, we need to use groups command. For instance,

groups user_name

We can use various command line tools to manage groups. Now, we will create a new user (“username”) and shuffle its primary and secondary groups.

Add user to a group and make changes to its Primary Group

STEP РI: We need superuser privileges to make any changes, otherwise contact your System Administrator for assistance.

Next, add a new user –

sudo useradd username

Now, we will be creating a password for the user –

sudo passwd username

Check its default group name with the help of command –

sudo groups username

STEP – II: In this step, we will be creating two groups – primary and secondary.

sudo groupadd groupprimary
sudo groupadd groupsecondary

STEP – III: Now, with the help of a usermod command, we would change primary and secondary group of our user –

sudo usermod -g groupprimary -G groupsecondary username

-g, the user’s primary group and -G for its secondary group. Then, we will verify it with command –

groups username

In conclusion, we have discussed the command line tools available to add user to a group in Ubuntu or Linux Mint. Then, we learnt how to shuffle its primary and secondary groups.