M
M
Maxim2019-06-29 06:19:57
linux
Maxim, 2019-06-29 06:19:57

How to understand primary and secondary group in Linux?

Linux users can be members of two different types of groups. First, there is the main group. Each user must be a member of a primary group, and there is only one primary group. When files are created, the main group becomes the owner of the group of those files. Users can also access all files that their primary group has access to. Membership in the primary user group is defined in /etc/passwd; the group itself is stored in the configuration file /etc/group.
So I didn't understand. I create a user user, a user group is automatically created for it. This group is the main one. user creates files/directories and they automatically become members of the primary group user?
Next come the secondary groups. We have user and user2. Create a two_users group, add user and user2 there, now they have a secondary group. Is it for such cases that secondary groups are needed so as not to add, for example, user2 to the primary group user?
In general, I am confused and / or do not understand.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-06-29
@alexr64

Primary, secondary... Keep it simple.
The user must be in at least one group. As a maximum - at least in all.
Only if you do not specify a group when creating. Specified the group when creating the user - he went there. Not specified, the system creates a group with the user's name automatically in order to fulfill the condition about "at least in one group".

S
sash999, 2019-06-29
@sash999

Well, in general, yes. Let's say you have a directory where you need to give write-read access to two users except for the owner and no one else. Create a group two_users, using usermod -G -a add the necessary users to it and set the rights to the directory - chgrp two_users directory; chmod 770 directory. There are other cases when secondary groups are needed, this is just the simplest and most obvious.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question