How To Add A Group In Linux
Changing the group a user is associated to is a fairly easy task, but not everybody knows the commands, especially to add a user to a secondary group. We'll walk through all the scenarios for you.
User accounts can be assigned to one or more than groups on Linux. You can configure file permissions and other privileges by group. For example, on Ubuntu, but users in the sudo group can use the sudo
command to gain elevated permissions.
If you're using a new Linux laptop, you lot might have some type of GUI interface to configure these settings (depending on the distribution that you're running, at least) only realistically it'due south about always easier to only drop down to the terminal and type out a few commands, so that'due south what nosotros're showing you today.
Add together a New Group
RELATED: What'southward the Difference Between Sudo and Su in Linux?
If you want to create a new grouping on your system, apply the groupadd
command following control, replacing new_group with the name of the group you want to create. You'll demand to use sudo with this control every bit well (or, on Linux distributions that don't use sudo
, you lot'll need to run thesu
command on its ain to gain elevated permissions earlier running the control).
sudo groupadd mynewgroup
Add an Existing User Business relationship to a Group
To add together an existing user account to a group on your system, use the usermod
command, replacing examplegroup
with the name of the group y'all desire to add together the user to andexampleusername
with the proper noun of the user you want to add.
usermod -a -Thousand examplegroup exampleusername
For case, to add the user geek
to the group sudo
, use the post-obit command:
usermod -a -Grand sudo geek
Modify a User's Primary Group
While a user account can be part of multiple groups, one of the groups is always the "chief group" and the others are "secondary groups". The user's login process and files and folders the user creates will exist assigned to the master group.
To change the master group a user is assigned to, run the usermod
command, replacingexamplegroup
with the proper name of the grouping you desire to be the primary and exampleusername
with the name of the user account.
usermod -chiliad groupname username
Note the -1000
here. When you apply a lowercase thousand, you assign a primary group. When you use an capital letter -G
, as above, yous assign a new secondary group.
RELATED: How to Control sudo Access on Linux
View the Groups a User Account is Assigned To
To view the groups the current user business relationship is assigned to, run the groups
command. You'll see a list of groups.
groups
To view the numerical IDs associated with each group, run the id
control instead:
id
To view the groups another user business relationship is assigned to, run the groups
command and specify the proper name of the user account.
groups exampleusername
You tin can also view the numerical IDs associated with each group by running the id
command and specifying a username.
id exampleusername
The commencement group in the groups
listing or the group shown afterward "gid=" in the id
listing is the user account's main grouping. The other groups are the secondary groups. And so, in the screenshot below, the user account's main group is example
.
Create a New User and Assign a Group in One Command
You may sometimes want to create a new user account that has admission to a item resource or directory, like a new FTP user. You can specify the groups a user account will be assigned to while creating the user account with the useradd
command, like so:
useradd -Thousand examplegroup exampleusername
For case, to create a new user account named jsmith and assign that business relationship to the ftp group, y'all'd run:
useradd -1000 ftp jsmith
Yous'll want to assign a password for that user later on, of course:
passwd jsmith
RELATED: How to Use the FTP Command on Linux
Add a User to Multiple Groups
While assigning the secondary groups to a user business relationship, you tin can easily assign multiple groups at one time by separating the list with a comma.
usermod -a -Thousand group1,group2,group3 exampleusername
For example, to add together the user named geek to the ftp, sudo, and example groups, yous'd run:
usermod -a -G ftp,sudo,example geek
You tin can specify as many groups as you like—just separate them all with a comma.
RELATED: The Best Linux Distributions for Beginners
View All Groups on the Organisation
If you desire to view a list of all groups on your organisation, you tin can utilize the getent
command:
getent grouping
This output volition too show you which user accounts are members of which groups. So, in the screenshot below, we tin see that the user accounts syslog and chris are members of the adm group.
That should cover everything you lot demand to know about adding users to groups on Linux.
RELATED: The All-time Linux Laptops of 2022
How To Add A Group In Linux,
Source: https://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/
Posted by: brinsonthund1953.blogspot.com
0 Response to "How To Add A Group In Linux"
Post a Comment