How to Add User To Group - Linux

How to Add User To Group - Linux

Add a user to group is a very easy and simple in Linux. You have two group for adding user that is primary group and secondary group in Linux system. you can add user either using useradd commands or usermod commands. If you use useradd command then you need to create a new user and add information of that user. If you use usermod commands than you just need to modify the existing user account to add user to the group.

If you want to add user to secondary group then use the following commands

Adding New Group:

If you want to add user to group then first you need to add group by simply using given commands.

Syntax:

groupadd <name of group>

Adding the existing user to Group:

If you want to add existing user to group then use the given command

Syntax:

usermod –a –G <group name> <username>

Changing User’ Group:

If you want to change the primary group to another than use given command.

Syntax:

usermod – g <group name> <user name>


Show Group Assignment of User:

If you want to see the group assignment of user then uses the given commands.

Syntax:

id <user name>

Or

groups <user name>

View Group List:

For group list use the following commands

Syntax:

groups

Using one command To Add User and Assign To Group:

If you need to add a new user that has accessed resources or directory than use the given commands.

Syntax:

useradd – g <group name> username

If you set the password for the user

Syntax:

passwd <user name>

Adding User to Multiple Group:

For adding the user to multiple group via using the given commands

Syntax:

usermod –a –G <group name 1>,<group name 2>,<group name3> <username>
Author
Jaishree
Views
2,175
First release
Last update
Rating
0.00 star(s) 0 ratings
Top