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

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

Linux laptop showing a bash prompt
fatmawati achmad zaenuri/Shutterstock.com

To include a consumer to a team, open the Terminal, then kind “sudo usermod -a -G examplegroup exampleusername” into the window. Exchange “examplegroup” and “exampleusername” with the group and username you want to modify.

Modifying the team a consumer is linked to is a relatively straightforward process, but not every person understands the commands, specifically to increase a person to a secondary group. We’ll walk as a result of all the eventualities for you.

User accounts can be assigned to a person or additional groups on Linux. You can configure file permissions and other privileges by team. For case in point, on Ubuntu, only buyers in the sudo team can use the sudo command to attain elevated permissions.

If you are utilizing a new Linux notebook, you might have some form of GUI interface to configure these options (depending on the distribution that you are functioning, at least) but realistically it is virtually always less difficult to just fall down to the terminal and kind out a couple of commands, so that is what we’re demonstrating you nowadays.

Incorporate a New Team

Linked: What’s the Change Concerning Sudo and Su in Linux?

If you want to make a new team on your technique, use the groupadd command adhering to command, changing new_group with the name of the team you want to make. You are going to have to have to use sudo with this command as well (or, on Linux distributions that do not use sudo, you are going to want to run the su command on its own to obtain elevated permissions right before working the command).

sudo groupadd mynewgroup

Add an Current Consumer Account to a Group

To add an current user account to a team on your program, use the usermod command, changing examplegroup with the identify of the group you want to add the person to andexampleusername  with the title of the consumer you want to include.

usermod -a -G examplegroup exampleusername

For example, 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.

Improve a User’s Primary Group

While a user account can be part of multiple teams, just one of the teams is usually the “primary group” and the many others are “secondary groups”. The user’s login system and information and folders the consumer creates will be assigned to the key team.

To alter the main team a consumer is assigned to, run the usermod command, replacingexamplegroup  with the name of the group you want to be the major and exampleusernamewith the title of the user account.

usermod -g groupname username

Be aware the -g here. When you use a lowercase g, you assign a most important team. When you use an uppercase -G , as earlier mentioned, you assign a new secondary team.

Changing the Geek user's primary group to example.

Connected: How to Regulate sudo Accessibility on Linux

Perspective the Teams a Person Account is Assigned To

To look at the groups the existing user account is assigned to, run the groups  command. You’ll see a list of groups.

teams

To perspective the numerical IDs related with each individual team, run the id  command instead:

id

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

To view the groups a further user account is assigned to, operate the groups command and specify the identify of the consumer account.

teams exampleusername

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

id exampleusername

The very first team in the teams record or the group demonstrated soon after “gid=” in the id listing is the person account’s most important team. The other groups are the secondary teams. So, in the screenshot underneath, the user account’s primary team is case in point.

Checking the groups the geek user belongs to.

Produce a New User and Assign a Group in 1 Command

You could in some cases want to build a new person account that has obtain to a unique source or directory, like a new FTP user. You can specify the teams a person account will be assigned to although creating the person account with the useradd command, like so:

useradd -G examplegroup exampleusername

For illustration, to create a new user 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 person later on, of course:

passwd jsmith

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

Linked: How to Use the FTP Command on Linux

Incorporate a Consumer to Several Groups

While assigning the secondary teams to a person account, you can easily assign many teams at the moment by separating the record with a comma.

usermod -a -G group1,group2,team3 exampleusername

For case in point, to include the person named geek to the ftp, sudo, and case in point teams, you’d run:

usermod -a -G ftp,sudo,instance geek

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

Adding a user to multiple groups with one command.

Linked: The Most effective Linux Distributions for Inexperienced persons

Look at All Teams on the Program

If you want to check out a checklist of all teams on your technique, you can use the getent command:

getent group

This output will also demonstrate you which person accounts are associates of which teams. So, in the screenshot underneath, we can see that the user accounts syslog and chris are associates of the adm group.

List of groups available on the system.

That ought to protect almost everything you require to know about introducing buyers to groups on Linux.

Similar: The Finest Linux Laptops of 2022

Leave a Reply