How to Add Users to Groups in Ubuntu Linux

This article provides a guide for adding users to groups in Ubuntu Linux, a function that helps regulate account access to resources. It distinguishes between primary and secondary groups, with a new account automatically joining the corresponding primary group. The text also specifies how to add a user to a group, change a user’s primary…

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

A group is a container that can organize or administer user accounts. Accounts in the same group will access and manage resources belonging to that group.

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

A primary group similar to the account name will also be created when you create a new account. 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 helps 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 restricting users’ resource access. 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 to exist already.

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

sudo usermod -a -G sudo geekrewind

When adding a user to a new group, you use the -a (append) command. If the group does not exist, the command will return an error that the group does not exist.

Change a user’s primary group in Ubuntu Linux

As stated above, whatever resources users create 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 command option.

sudo usermod -g groupname username

For example, you use the commands below to change the primary group of the user geekrewind to developers.

sudo usermod -g developers geekrewind

When creating a user account, you can specify a user’s primary and secondary groups. For example, use the below to create a new geekrewind account and set 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!

Conclusion:

  • Adding users to groups in Ubuntu Linux is essential for organizing and administering user accounts.
  • Administrators can effectively manage resource access and permissions by understanding the distinction between primary and secondary groups.
  • The steps outlined provide clear guidance on adding users to single and multiple groups and changing a user’s primary group.
  • Readers can refer to the provided link for instructions on listing all groups in Ubuntu Linux, enhancing their understanding of user and group management.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *