December 6, 2022


Inspire the Next

Add a User to a Group (or Second Group) on Linux

Linux laptop showing a bash prompt
fatmawati achmad zaenuri/

To increase a person to a team, open the Terminal, then form “sudo usermod -a -G examplegroup exampleusername” into the window. Swap “examplegroup” and “exampleusername” with the group and username you want to modify.

Transforming the group a user is linked to is a relatively quick endeavor, but not all people understands the instructions, specifically to insert a user to a secondary team. We’ll walk by way of all the situations for you.

User accounts can be assigned to a single or more teams on Linux. You can configure file permissions and other privileges by group. For illustration, on Ubuntu, only customers in the sudo team can use the sudo command to acquire elevated permissions.

If you’re applying a new Linux notebook, you could possibly have some sort of GUI interface to configure these options (dependent on the distribution that you’re managing, at the very least) but realistically it’s almost normally much easier to just drop down to the terminal and type out a few commands, so that’s what we’re displaying you these days.

Incorporate a New Group

Connected: What’s the Variance Concerning Sudo and Su in Linux?

If you want to make a new team on your technique, use the groupadd command adhering to command, replacing new_group with the name of the group you want to build. You are going to want to use sudo with this command as well (or, on Linux distributions that don’t use sudo, you will have to have to operate the su command on its individual to gain elevated permissions before managing the command).

sudo groupadd mynewgroup

Add an Existing Person Account to a Group

To include an current consumer account to a team on your process, use the usermod command, replacing examplegroup with the name of the team you want to increase the consumer to andexampleusername  with the title of the user you want to increase.

usermod -a -G examplegroup exampleusername

For illustration, to increase the consumer geek to the group sudo , use the following command:

usermod -a -G sudo geek

Adding the user "Greek" to the sudoers group.

Modify a User’s Primary Group

Though a user account can be aspect of numerous groups, 1 of the teams is often the “primary group” and the many others are “secondary groups”. The user’s login approach and documents and folders the user makes will be assigned to the major group.

To modify the principal group a person is assigned to, run the usermod command, changingexamplegroup  with the identify of the group you want to be the major and exampleusernamewith the name of the person account.

usermod -g groupname username

Note the -g below. When you use a lowercase g, you assign a major team. When you use an uppercase -G , as higher than, you assign a new secondary group.

Changing the Geek user's primary group to example.

Connected: How to Control sudo Obtain on Linux

Look at the Teams a Person Account is Assigned To

To watch the groups the latest person account is assigned to, operate the teams  command. You will see a record of groups.


To view the numerical IDs connected with just about every team, run the id  command as a substitute:


Checking what groups there are, and what their numerical IDs are.

To look at the groups another person account is assigned to, run the teams command and specify the title of the consumer account.

groups exampleusername

You can also watch the numerical IDs connected with every group by operating the id command and specifying a username.

id exampleusername

The very first group in the teams checklist or the group revealed following “gid=” in the id record is the person account’s main group. The other teams are the secondary teams. So, in the screenshot down below, the consumer account’s main group is instance.

Checking the groups the geek user belongs to.

Generate a New Consumer and Assign a Team in 1 Command

You may possibly sometimes want to build a new consumer account that has obtain to a certain useful resource or directory, like a new FTP person. You can specify the groups a user account will be assigned to even though generating the user account with the useradd command, like so:

useradd -G examplegroup exampleusername

For instance, to build a new person account named jsmith and assign that account to the ftp group, you’d operate:

useradd -G ftp jsmith

You’ll want to assign a password for that consumer later on, of study course:

passwd jsmith

Creating a new user and simultaneously adding it to a group.

Similar: How to Use the FTP Command on Linux

Insert a Consumer to Many Groups

Even though assigning the secondary teams to a consumer account, you can easily assign various teams at at the time by separating the listing with a comma.

usermod -a -G group1,team2,team3 exampleusername

For instance, to increase the user named geek to the ftp, sudo, and case in point teams, you’d operate:

usermod -a -G ftp,sudo,example geek

You can specify as quite a few groups as you like—just individual them all with a comma.

Adding a user to multiple groups with one command.

Related: The Most effective Linux Distributions for Inexperienced persons

Look at All Teams on the Method

If you want to perspective a checklist of all groups on your technique, you can use the getent command:

getent team

This output will also display you which user accounts are users of which teams. So, in the screenshot beneath, we can see that the user accounts syslog and chris are customers of the adm group.

List of groups available on the system.

That should cover almost everything you want to know about adding customers to groups on Linux.

Connected: The Most effective Linux Laptops of 2022