Linux - Set file permission using octal
2K views
Nov 28, 2024
Linux - Set file permission using octal
View Video Transcript
0:00
So hope you have understood how to change the permission by using this symbolic method
0:05
Now let us begin to change the permission by using an octal numbers
0:10
Same way like you have used operators into the previous video to change the permission
0:15
Here we will be using the numbers. So basically the octal numbers start from 0 till 7
0:21
It means 0 to 7. That means it is 8. So these all 8 numbers we can use for setting the permissions to your file or a directory
0:29
or a directory. Now very first you can see 0. If I define 0 means there is no permission closely
0:35
So you can see here into the group we do not have any permission, neither read, write or execute
0:41
Same way we use 1. 1 is reserved for your execute permission
0:46
So if I want to define any execute permission, I'll just define the permission as 1
0:51
So it will take it as no read, no right and just execute, hyphen, hyphen x
0:57
same way if we use 2 is reserved for your right formation
1:02
so basically if I want to define only right formation to a particular group
1:07
I can use 2 as a permission so it will provide you
1:11
hyphen w and hyphen the next we have number 3 so basically this 3 is not reserved
1:19
this 3 is addition of your 1 and 2 so where the 1 is your execute permission and 2 is your right permission
1:26
So if I define number 3, it will calculate your 2 and 1 and it will make it 3 where it will provide you the permission as read and execute
1:36
Basically it will provide you the permission as write and execute. So you can find here no read but you have write and execute permission
1:45
The next we have that is 4. 4 is completely reserved for your read permission
1:51
So if you want to specify a read permission, you'll just define the group as a number 4
1:56
So it will provide you only read without write and execute. Same this is you have that is 5
2:02
5 means we are going to add this 4 along with this 1. 4 means read permission and while 1 we have that is for execute permission
2:12
So if I want to define any particular user or any particular group for the permission as a read and execute
2:19
so I just define the number as 5. So it will get the permission as R-hyphen X means no right
2:25
right formation now here we have six six again includes your read and right because
2:31
six includes four plus two four means read and two means right so you can find
2:37
four means rate and two plus right so if I want to define any particular
2:41
owner group or others as read and write formation I can give number six So you can see into the attribute we have R but no execute formation
2:53
But what if I want to provide the complete access to everything
2:56
Means we can say a full control formation. So we'll just have 7
3:01
7 means including your read, write and execute. Read, 4, write, 2 and execute 1
3:09
So calculating all the 3, adding this 3 will get number 1. this three will get number seven. So if you define the permission as seven, it will directly
3:16
take read, write and execute for your group owner or your others. So this is the way how generally
3:21
we use octal numbers for defining the formation. So let us see this practically into our Linux
3:27
terminal. Now here we can see the number of directory and file we do have into this desktop
3:35
So I have to one file and one directory, two content we have
3:41
And now I'm going to change the permission of this directory. This is folder 1
3:45
So right now the permission which we have for the folder 1 is read, write, execute for the owner
3:50
rewrite and execute for the group, and read and execute for the others
3:55
Now if I want to set the permission or change the permission using my octal numbers
4:00
I'll be giving the owner permission first. Now for example, I want to change the owner permission
4:05
to read and write only. So for read, I have the number assigned that is 4 and for
4:12
right I have 2. So I'll just add both of it that is 6. And then for group I want to
4:19
assign read and execute that is R and X. For read we have 4 and for execute we have 1. So
4:27
it will be 5 and I want to define only read permission to my others. So I can define only
4:34
Only read permission that is 4. Now I need to define the directory name
4:42
Just check it out. Here you can see it's changed. The owner is having read and write group, read and execute while others only read
4:55
Same way if I want to change the permission. Read write and execute to my owner so I'll use 7. Read and
5:04
execute to my group. So I'll just keep it 5 itself and no permission to others. I'll keep
5:12
0 for the same directory folder 1. Check into the allow. Now you have full control for owner
5:21
read and execute for the group and nothing for others. So this is how you can change the folder
5:27
formation Now I just take an scenario where I have a folder into a folder For example I just move into the folder 1 There is nothing into the folder 1 I going to create a directory into the folder 1
5:40
Into folder 1, I'm going to create a directory with name Data 1 and Data 2, for example
5:50
Now you can see the permissions which we have for Data 1 and Data 2 is completely different than what we have into the folder 1
5:57
into folder 1 we have set the permission as read write and execute for owner read and execute
6:06
for the group and for others we haven't defined any permission but you can see this
6:11
sub directory which we have created after defining the permission it's containing all together a different permission that it is containing read write and
6:21
execute for the owner same the group has the full control permission and the other
6:27
has written execute only. That's because Linux is more secure for defining the
6:34
permission. Generally even though if it is a parent and child relation
6:39
folders or you have the child directories it won't inherit the permission which
6:43
we have for the parent directory or by tone. So unlike like where Windows we
6:48
need to define the permissions for our child directories as well. So for
6:55
defining the child directory permissions what we can do is is we can use the same command CHMode hyphen capital R for recursive
7:08
Directors, I'm just going to define the folder name and I'm going to refine the permission
7:13
what we require. So I'm going to define the permission 750 even I want for the subfolders of your folder 1
7:23
That is data 1 and data 2. And next I'll go inside the directory
7:27
folder 1 and we can check the permission of your data 1 and data 2 you can see it almost
7:34
inherited the permission which we had on folder 1 but only this is for this two data again if
7:40
I create any other directory you will find that it's again containing the default formation
7:53
now what is this default formation this default formation this default formation which
7:57
generally get by UMass number. So this UMass number we should know
8:03
What is the UMass number? It containing 0,002. That means it generally basically get added from 4 times 7 this number that is the UMass number So whatever the number you get So here you will be getting 777 and this minus 2 that is your UMass number That means you have
8:30
just we can say you can remove this number and zero. So you have three sevens because this is set for this
8:35
special kind of formation we are going to see letter. So right now you have this three seven which we are
8:41
using for owner group and other formation and this three digits zero zero two
8:46
So if you divide it, you will be getting 7, 7 and then 5
8:54
This is the permission of what you get, right? So let us check, is that the same permission we are getting for data 3
9:01
7, 7 and 5. So that's the reason because of UMass, you are getting this default permission for each and every directories
9:11
Now, how we can change the UMask value? If I want to change the UMask value so that all my directories which I generally create should get 7-50 permission
9:22
So for that, I just need to make the UMASC value in such a way. For 7, I'll give 0
9:27
For 5, I'll give 2 because it will get subtracted from the 7 itself
9:33
So the remaining I'll have that is 5. And for my others, I'll give 7 because from 7 it will be subtracted and we will be able to get
9:44
750 right so let us check after creating a directory right now I do have this three
9:51
directories and I'm going to add a new directory with name data 4 again check
9:59
this directory all together has a different permissions unlike at this directory so here it has read write and execute read and execute and execute and
10:10
nothing for your others. That is because of you must know not only on this file but
10:15
this will be reflecting all the directories if you create anywhere like even if I've
10:20
created on desktop can check for doc one even you have the same permission so read
10:33
and execute for your owner read and execute for your other this is a group members
10:38
and no permission for your others. So this is how we can manage the file permission using your CH more command and set the UMass
10:48
So the default value of UMASC is 000 to itself in any of the distributors
10:57
So this is we have seen about the permissions by using the occult permissions
11:01
Now we are going to see how we can use the G-O-ID and SUID permissions into the next video
#Computer Education
#Educational Software
#Programming