0 0 votes
Article Rating
linux,user,usermod,group,account
assign users to groups in Linux

Add an Existing User Account to a Group

To add an existing user account to a group on your system, use the usermod command, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.

usermod -a -G examplegroup exampleusername

Change a User’s Primary Group

While a user account can be part of multiple groups, one of the groups is always the “primary group” and the others are “secondary groups”. The user’s login process and files and folders the user creates will be assigned to the primary group.

To change the primary group a user is assigned to, run the usermod command, replacingexamplegroup  with the name of the group you want to be the primary and exampleusernamewith the name of the user account.

usermod -g groupname username

View the Groups a User Account is Assigned To

To view the groups the current user account is assigned to, run the groups  command. You’ll see a list of groups.

groups exampleusername

Add a User to Multiple Groups

While assigning the secondary groups to a user account, you can easily assign multiple groups at once by separating the list with a comma.

usermod -a -G group1,group2,group3 exampleusername

View All Groups on the System

If you want to view a list of all groups on your system, you can use the getent command:

getent group


Chris

Chris

Just me, need more info?

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x