How to Create a Group and Add Users to a Group

How to Create a Group, Add Users to a Group and Change the Primary Group of a User

In the previous Learning Terminal tutorial, we have learned how to change the user owner of a file and also how to use it group granted access to the file. Group it contains a collection user pre-set based on the desired specifications.

Grouping user into the group based on the permissions to be granted important in file management and users. That way you will be able to organize groups user whichever has access to a service, a file, a folder or something else.

In this tutorial, we will learn about group on Linux, how do I create a user groups new one, how to add user to a group and how to change primary group from a users.

How to Create a New Group

First, we will learn first how to make a group new. To make a group new, the method is very easy, you only need to use the command groupadd and followed by the name group new to be created.

To create, delete or replace a group a useryou must use super user “root” or user ordinary people who have administrative privileges or the ability to execute commands sudo.

For example, you want to create a group with the name “sudoway”, you can do this by using the following command:

sudo groupadd sudoway

Then it will create a group new with the name “sudoway”. To prove whether you have succeeded in making a group new, you can use a command like the following:

cut -f1 /etc/group

Then a list of groups will appear group that is on your computer complete with a list user what’s inside group is as in the following image:

View a list of groups that exist on Linux
View a list of groups that exist on Linux

At the very bottom of the image we can see group which we just created is named “sudoway”, group it doesn’t have user inside it.

How to Add User to Group

by default every group in an empty state without user inside it. To add a user into a groups, you can use the command usermod and use parameter-a -G‘ in front of him.

For example, you want to add a user named “ikhsan” (pre-existing) into group named “sudoway” that we just created, you can do this by using a command like the following:

sudo usermod -a -G sudoway ikhsan

Then user named “ikhsan” will become a member group “sudoway”. To prove it, you can see group from a user by using the command groups and followed by username from user what you want to see in front of him, like this:

groups ikhsan

Then you will appear a list group from user named “ikhsan” as in the image below. There you will see group “sudoway” in the list group from user “ikhsan”, which means the command we used earlier to add user “sincere” to group “sudoway” did the trick.

Adding a User to a Group on Linux
Adding a User to a Group on Linux

How to Change a User’s Primary Group

On Linux, a user can have more than one groups. Among many group where is a user can become a member in it, one of them will become primary group from user the.

Group primary is group main of a users. When a file is created, automatically defaults, user the creator of the file will be the owner of the file and primary group from the user who created the file it will be group which has access rights to the created file.

a user can only have one fruit primary group, all group other than primary group called secondary group. You can change primary group from a user by using the command usermod and add parameters “-g” in front of him.

For example, you want to make group “sudoway” becomes primary group from user named “ikhsan” before, you can do this by using a command like the following:

sudo usermod -g sudoway ikhsan

To prove whether you can use the command ikhsan groups as in the image below:

Changing the Primary Group of a User in Linux
Changing the Primary Group of a User in Linux

In the image below you will see group “sudoway” is at the top of the list group from user “ikhsan”, which means “sudoway” has become primary group from user “sincere”.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *