In certain conditions, you possibly need to add a new user to a group of Linux. Besides, when you have an existing user, you can still add it to Linux. In this case, you need to know the ways of Linux add user to group. When you have known the ways, you will have Linux list group both for primary and secondary ones. To know more about those groups, let’s see the explanation below.
Two Groups’ Kinds of Linux Add User to Group
You have to know that in Linux add user to group, there are two kinds of groups. What are they? Here are the available for you.
1. Primary Group
The first kind of group is named Primary Group. As you know that it applies and shows you when you log in. Please remember that most user has the same name as your login name. Then, this kind of group is usually used by default when you create new files or directories, executing commands, or modifying files,
2. Secondary Group
What about this group? The second Linux add user to group is a secondary group. Well, it is also called AKA Supplementary Groups. It shows that you are a primary group member. What does it mean? You can know this information to get a better understanding. If a file or directory belongs to the www-data group that is used by the webserver process, what will happen? Yea, all members of the www-data group can read or modify these files directly.
The Tutorials
There are some tutorials of Linux add user to group that you can know. Are you curious about them? Just let’s check them out in detail!
1. Make a new user
When you want to create a new user, what should you do? You have to know first that you can add Linux users via the commands of the useradd or adduser. Useradd is related to the Linux systems. On the other hand, the command of adduser is classified into user-friendly. Furthermore, both commands show functionality.
2. Change the primary group
This tutorial of Linux add user to group means that it changes the primary group of a user. You can try some ways to do it. The first way is using the command of usermod. You will find this information “$ sudo usermod –g www-data foobar”. The option of lowercase -g refers to a primary group. Then, it will become:
$ id foobar
uid=1001 (foobar) gid=33 (www-data)
3. Make or delete a group
To make or delete a group in Linux, you can use the command of groupadd and groupdel. If you use the groupadd command, you can make a new group that is group1. You will get this notification:
sudo groupadd group1
sudo adduser foobar group1
Besides, you can also remove group1 using the command of groupdel. By using this command, you will find this following information:
sudo groupdel group1
What does it mean? Yea, it will remove the memberships of this group.
4. Get user ID
The next tutorial of Linux add user to group that you can know is getting the user ID and also group information. In this case, you are allowed to use the id command. This command is usually used to indicate all groups’ memberships and the user information. You will find this:
id foobar
id=1001 (foobar) gid=1001 (foobar) g
$ id foobar
uid=1001 (foobar) gid=1001 (foobar)
The gid or group ID is known as the primary user group and groups are the secondary group.
5. Add or change users in a secondary group
It will show you the way to add the foobar user to www-data as a secondary group. You can use the easiest way that is via the command of the adduser. Here it is:
sudo adduser foobar www-data
Then, you can also find the user of secondary group. Just find this information!
$ id foobar
uid=1001 (foobar) gid=1001 (foobar)
Besides, you can use another way by using the command of usermod. The command is available below.
$ sudo usermod –G www-data foobar
The meaning of uppercase –G is the secondary group.
Well, that’s all about Linux add user to group by knowing the kinds and also the tutorial in it. Please understand it well!