May 2, 2024

Stereo Computers

Things Go Better with Technology

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

4 min read
Add a User to a Group (or Second Group) on Linux

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

To increase a consumer to a group, open up the Terminal, then style “sudo usermod -a -G examplegroup exampleusername” into the window. Switch “examplegroup” and “exampleusername” with the group and username you want to modify.

Switching the team a person is linked to is a reasonably effortless undertaking, but not all people is aware the instructions, specially to insert a user to a secondary group. We’ll walk via all the situations for you.

Consumer accounts can be assigned to 1 or much more groups on Linux. You can configure file permissions and other privileges by group. For example, on Ubuntu, only customers in the sudo group can use the sudo command to get elevated permissions.

If you’re working with a new Linux laptop, you could have some form of GUI interface to configure these settings (dependent on the distribution that you’re functioning, at least) but realistically it’s nearly generally easier to just fall down to the terminal and variety out a number of instructions, so which is what we’re demonstrating you now.

Insert a New Group

Similar: What is the Variation Involving Sudo and Su in Linux?

If you want to produce a new team on your program, use the groupadd command pursuing command, changing new_group with the name of the group you want to create. You are going to require to use sudo with this command as well (or, on Linux distributions that never use sudo, you are going to have to have to operate the su command on its very own to obtain elevated permissions before operating the command).

sudo groupadd mynewgroup

Incorporate an Present User Account to a Group

To include an existing consumer account to a team on your method, use the usermod command, replacing examplegroup with the title of the team you want to incorporate the user to andexampleusername  with the identify of the consumer you want to add.

usermod -a -G examplegroup exampleusername

For example, to include the consumer geek to the team sudo , use the next command:

usermod -a -G sudo geek

Adding the user "Greek" to the sudoers group.

Improve a User’s Primary Team

Even though a person account can be element of multiple teams, a single of the teams is often the “primary group” and the many others are “secondary groups”. The user’s login procedure and information and folders the person creates will be assigned to the most important group.

To improve the main group a user is assigned to, run the usermod command, changingexamplegroup  with the identify of the group you want to be the most important and exampleusernamewith the identify of the person account.

usermod -g groupname username

Observe the -g below. When you use a lowercase g, you assign a major team. When you use an uppercase -G , as over, you assign a new secondary team.

Changing the Geek user's primary group to example.

Similar: How to Handle sudo Obtain on Linux

See the Groups a Person Account is Assigned To

To see the teams the present-day user account is assigned to, operate the groups  command. You’ll see a list of teams.

groups

To view the numerical IDs related with each team, operate the id  command in its place:

id

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

To check out the teams an additional consumer account is assigned to, operate the teams command and specify the name of the person account.

teams exampleusername

You can also see the numerical IDs involved with every single group by working the id command and specifying a username.

id exampleusername

The initially group in the groups record or the team revealed following “gid=” in the id checklist is the user account’s primary team. The other groups are the secondary groups. So, in the screenshot beneath, the person account’s primary team is example.

Checking the groups the geek user belongs to.

Generate a New Consumer and Assign a Team in 1 Command

You may well occasionally want to build a new user account that has entry to a individual useful resource or listing, like a new FTP person. You can specify the groups a person account will be assigned to even though making the person account with the useradd command, like so:

useradd -G examplegroup exampleusername

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

useradd -G ftp jsmith

You are going to want to assign a password for that user later on, of training course:

passwd jsmith

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

Relevant: How to Use the FTP Command on Linux

Include a Person to A number of Teams

Though assigning the secondary groups to a consumer account, you can very easily assign numerous groups at when by separating the list with a comma.

usermod -a -G group1,team2,group3 exampleusername

For example, to add the person named geek to the ftp, sudo, and illustration teams, you’d run:

usermod -a -G ftp,sudo,example geek

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

Adding a user to multiple groups with one command.

Associated: The Ideal Linux Distributions for Beginners

Check out All Teams on the Method

If you want to check out a record of all groups on your process, you can use the getent command:

getent group

This output will also show you which user accounts are members of which groups. So, in the screenshot below, we can see that the consumer accounts syslog and chris are customers of the adm group.

List of groups available on the system.

That must include all the things you want to know about including users to groups on Linux.

Related: The Ideal Linux Laptops of 2022

Leave a Reply

stereocomputers.com | Newsphere by AF themes.