In Linux, the access to the file system is managed through the ownership and file permissions. 1
File permissions, or file modes, specify who can access, change or execute a file on a Linux System. 2
It ensures that only authorized users and processes can access files and directories. 3
This is a key concept related to the entire system 4
security. In this lecture will discuss the basics of Linux permissions model. 5
Each file has an owner and a group. 6
By default, the owner is the user who creates the file and the group is the primary group of that user. 7
Note that it's not mandatory for the owner of the file to belong to the group owner of the same file. 8
The ownership of a file or directory can be changed only by root using the change owner and change group 9
commands. We will take a look at them later in this section. 10
For each file of the system, the permissions are assigned to three different categories of users: 11
the file owner, the group owner and others, anyone else or the whole world. 12
There are three file permissions types that apply to each category: the read permission (r) 13
the write permission (w) and the execute permission (x). This concept allows you to specify which users are allowed 14
to read a file, 15
write to a file, or execute a file. 16
Note that the permissions have a different effect on directories compared to files. 17
So in a nutshell, there are three permissions (read, write and execute) for three categories of users: 18
(owner, group and others). To view the file’s permission run the ls -l command. 19
Now, let me explain to you the part of the output that is related to file permissions. 20
After the first character, which indicates the file type come 9 characters which represent the 21
file's permissions. 22
The first triplet shows the owner permissions, the second one the group permissions, and the last 23
triplet shows everybody else’s permissions. 24
The permissions for each class are always represented in a precise order: 25
read, write and execute. 26
Let's take another example! 27
The file owner, which is root has read and the write permissions, but doesn't have the execut permission. 28
A hyphen indicates the absence of a permission. 29
The group and the others have only the red permission, see how there's a hyphen instead of write and 30
execute for both the group and the others. 31
Let's see some more examples to deeply understand this concept. 32
In the next examples, I'll exchange the file's permissions using the the chmod command but please 33
don’t focus on the command. 34
I'll show you how to change the file's permissions and come back to the use of this command in the next 35
lecture. 36
Just focus on how the permissions are represented and what do they mean to a file. As an unprivileged 37
user 38
I'm creating a file and then I want to see its permissions. 39
I'm using a redirection: users.txt and let's see the permission of the file. 40
These are the file's permissions: the the owner has to both read and write permissions so it can view 41
and modify the file. 42
The user is allowed to view the file's contents. 43
And let's say w > users.txt 44
The user is allowed to modify the file contents is well. 45
Now, I'll remove to read permission for the user:chmod u-r and the file. 46
Now you see a hyphen instead of letter r for the user's permission. 47
I'm trying to view the file's contents, cat users.txtand ad the user is not allowed to view 48
the file contents any more. 49
Note that the user is still allowed to change the file contents. 50
It still has the write permission; now I'll remove the writ permission as well: chmode u-w 51
users.txt 52
There are no permissions for the user, for the owner; and the user cannot modify the file any more. 53
The same rules are applicable to the group owner and the others categories. Note that read and write 54
permissions are not applicable to the root user, even though root does not have those permissions 55
it can both view and change the files. 56
I'm temporarily becoming root by executing sudo su 57
I'm root 58
I'm creating a new file using a redirection. 59
And I'm removing all file's permissions: chmod 000 and the name of the file. 60
You can see that nobody has any permissions. 61
I'm trying to display the file's contents: cat interfaces.txt and root was allowed to 62
see the file's contents. 63
Or ls> interfaces.txt it was allowed to modify the file. 64
As the conclusion, we can say that the files read and write permissions are only for non privileged 65
users. And the last permission is execute. 66
A file which has this permission is a shell script or a command. All Linux commands have the execute 67
permission set. 68
If a file which represents a command doesn't have the execute permission set, then it cannot be executed, 69
it cannot be run. 70
We'll take a short break 71
and in the next lecture, I'll teach you how to represent file's permissions in numeric format.