How to add User to Group in Ubuntu Linux

This article describes the steps you can take to add users to groups in Ubuntu Linux.

A group is a container that can be used to organize or administer user accounts. Accounts in the same group will share resources provided to that group.

Every account on a Ubuntu Linux system belongs to one or more groups. There are two types of groups in Ubuntu Linux: Primary and secondary groups.

When you create a new account, a primary group similar to the account name will also be created. The account will automatically be added to the primary group. Resources (files, folders) created by the account will by default be assigned permissions of the primary group.

An account can be a member of both the primary and secondary groups. The secondary group is useful to assign permissions to accounts and services of other groups.

Below is how to add a user to a group in Ubuntu Linux.

Add a user to a group in Ubuntu Linux

As described above, you can create a group to restrict users’ access to resources. For example, if you add a user to the docker group, the user will inherit the group’s access rights and be able to run docker commands.

Below is a format to add a user to a group in Ubuntu Linux.

sudo usermod -a -G groupname username

Add a user to multiple groups.

sudo usermod -a -G group1,group2 username

The commands above assume that the groups you want to add a user already exist.

For example, to add the user geekrewind to the sudo group, you would run the following command:

sudo usermod -a -G sudo geekrewind

You use the -a (append) command option when adding a user to a new group. If the group doe not exists, the command will return an error message that the group does not exist.

Change a user’s primary group in Ubuntu Linux

As stated above, whatever resources a user creates in Ubuntu Linux will assume the rights and access the user’s default group. This will allow the users to have access to all the resources created.

In Ubuntu Linux, you can change a user’s primary group. To change a user’s primary group, use the usermod command followed by the -g option.

sudo usermod -g groupname username

For example, to change the primary group of the user geekrewind to developers.

sudo usermod -g developers geekrewind

You can also specify a user’s primary and secondary group when creating the account. Use the following below to create a new account named geekrewind and sets its primary group users and secondary groups to wheel and developers.

sudo useradd -g users -G wheel,developers geekrewind

To list all groups in Ubuntu Linux, read the post below.

How to list groups in Ubuntu Linux

That should do it!


This post showed you steps to add a user to a group in Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.