Hi Welcome You can highlight texts in any article and it becomes audio news that you can hear
  • Sun. Jul 13th, 2025

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

Byindianadmin

Oct 16, 2022
Include a User to a Group (or Second Group) on Linux
fatmawati achmad zaenuri/Shutterstock. com

To include a user to a group, open the Terminal, then type “sudo usermod -a -G examplegroup exampleusername” into the window. Change “examplegroup” and “exampleusername” with the group and username you wish to customize.

Changing the group a user is associated to is a relatively simple job, however not everyone understands the commands, specifically to include a user to a secondary group. We’ll stroll through all the circumstances for you.

User accounts can be appointed to several groups on Linux. You can set up file approvals and other opportunities by group. On Ubuntu, just users in the sudo group can utilize the sudo command to get raised consents.

If you’re utilizing a brand-new Linux laptop computer, you may have some kind of GUI user interface to set up these settings (depending upon the circulation that you’re running, a minimum of) however reasonably it’s generally much easier to simply fall to the terminal and type out a couple of commands, so that’s what we’re revealing you today.

Add a New Group

RELATED: What’s the Difference Between Sudo and Su in Linux?

If you wish to develop a brand-new group on your system, utilize the groupadd command following command, changing new_group with the name of the group you wish to develop. You’ll require to utilize sudo with this command too ( or, on Linux circulations that do not utilize sudo, you’ll require to run the su command by itself to get raised authorizations prior to running the command).

 sudo groupadd mynewgroup

Add an Existing User Account to a Group

To include an existing user account to a group on your system, utilize the usermod command, changing examplegroup with the name of the group you wish to include the user to and exampleusername with the name of the user you wish to include.

 usermod -a -G examplegroup exampleusername

For example, to include the user geek to the group sudo, utilize the following command:

 usermod -a -G sudo geek

Change a User’s Primary Group

While a user account can be part of numerous groups, among the groups is constantly the “main group” and the others are “secondary groups”. The user’s login procedure and files and folders the user develops will be designated to the main group.

To alter the main group a user is designated to, run the usermod command, changing examplegroup with the name of the group you wish to be the main and exampleusername with the name of the user account.

 usermod -g groupname username

Note the - g here. When you utilize a lowercase g, you designate a main group. When you utilize an uppercase - G, as above, you appoint a brand-new secondary group.

RELATED: How to Control sudo Access on Linux

View the Groups a User Account is Assigned To

To see the groups the present user account is designated to, run the groups command. You’ll see a list of groups.

 groups

To see the mathematical IDs connected with each group, run the id command rather:

 id

To see the groups another user account is appointed to, run the groups command and define the name of the user account.

 groups exampleusername

You can likewise see the mathematical IDs related to each group by running the id command and defining a username.

 id exampleusername

The very first group in the groups list or the group revealed after “gid=” in the id list is the user account’s main group. The other groups are the secondary groups. In the screenshot listed below, the user account’s main group is example

Create a New User and Assign a Group in One Command

You might in some cases wish to produce a brand-new user account that has access to a specific resource or directory site, like a brand-new FTP user. You can define the groups a user account will be appointed to while developing the user account with the useradd command, thus:

 useradd -G examplegroup exampleusername

For example, to develop a brand-new user account called jsmith and appoint that account to the ftp group, you ‘d run:

 useradd -G ftp jsmith

You’ll wish to appoint a password for that user later on, obviously:

 passwd jsmith

RELATED: How to Use the FTP Command on Linux

Add a User to Multiple Groups

While designating the secondary groups to a user account, you can quickly designate several groups at the same time by separating the list with a comma.

 usermod -a -G group1, group2, group3 exampleusername

For example, to include the user called geek to the ftp, sudo, and example groups, yo

Read More

Click to listen highlighted text!