Let's talk a little bit about the groups. The main purpose of the groups is to define a set of privileges 1
or permissions like read, write or execute for a given file that can be shared among the users within 2
the group. 3
You have to add the user to a group if you want to have the privileges of the group. In Linux 4
there are two types of groups that the user can belong to. 5
Primary or login group is the group that is assigned to the files that are created by the user. 6
The group id of the primary group is stored in/etc/ password and the group name in /etc/ group. 7
When a user creates a file, the user will be the owner of the file and its primary group will be the 8
group owner of the file. 9
Remember that in Linux a file is owned by both a user and a group. 10
I am creating a new file using touch. 11
And ls -l and the name of the file. 12
The user that runs t touch command is the owner and its primary group( having usually the same name as 13
the user) is the group owner. 14
Note that each user must belong exactly to one primary group. 15
And there are secondary or supplementary groups. A user can be a member of none or more secondary groups. 16
The secondary groups are stored in /etc/group Let's see how to find out the groups where a user belongs 17
to. To deeply understand how the user and the groups are connected 18
I'll show you directly in the files. 19
Then we'll take a look at the dedicated commands used to display the groups. 20
Let's take the current user and see its entry in /etc/password: grep (the user name) student and the file 21
/etc/passwd 22
This is its entry. 23
The 3rd field indicates the user ID and the 4th field indicates the primary grpup id, so from 24
the 4th field, we know that the primary group of this user has the ID 1000. 25
Let's search the group file for that ID. So grep 1000 the group file 26
So the user's primary group is a group with the same name, student in this case; typically no other 27
user will belong to this group. 28
Now let's find out the secondary groups of the user; to do that, I'll search for the user name in the 29
group file. 30
In fact, I'm opening it with less and searching for student. 31
The last field of each line indicates the users that belong to that group as a secondary group. 32
If there are more users belonging to the same group, which is quite common, then they are separated 33
by a comma. 34
Take a look at this line: both syslog and student users belong to the adm group. 35
Normally, you don't search through these files to find out to which groups a user belongs. There's the 36
groups command that does the job for you. 37
I'm running groups. 38
When executed without any arguments, the command will print out a list of all groups the current user 39
belongs to. 40
And the first group is the primary one. To get a list of all groups a specific user belongs to provide 41
the user name to the groups command 42
as argument, like: groups root and the user root belongs to only one group called root or 43
groups student 44
It belongs to these groups. 45
Another useful command is id. It prints information about the specified user and its groups and as the 46
group command, if the username is omitted, it shows information for the current user. 47
The command is showing the user ID 1000, the user's primary group and group id 48
and the user's secondary groups and their id.We'll take a short break and in the next lecture, I'll 49
show you how to create new user accounts.