Let's guys now talk about permissions and I'll explain you what is permission and how to modify permissions
for a particular file or directory.
And for example, here in this output for this file, three dot txt, you see that the owner of this
file is Bogdan and group is Bogdan.
And here are permissions first dash means that here you see file next three characters stand for permissions
for particular user.
In this case owner of the file owner is Bogdan Next three characters stand for permissions for other
users in the same group.
In this case, group is Bogdan.
And finally, three last characters stand for permissions for all remaining users that don't belong
to this particular group.
This are permissions.
Great.
Let's now quickly clean up this home directory for this particular user that we have created before.
And let me remove those two files one dot txt and two dot txt and this folder tmp and I'll do that under
bogdan's account and I will be able to do so because now I'm owner of those files here.
You see Bogdan everywhere.
Great.
Let's use command one dot txt or m two dot txt and r m dash r recursive tmp.
Actually I was able to use just a single command with multiple arguments type simply tmp space one dot
txt space to the txt.
All right.
Now I don't have any unnecessary files here in home directory for this user and I see only some hidden
files.
Great.
Now let's go back to root account and create a new file in home directory for this Bogdan user.
Let's go out of here and here as root user.
Let's touch new file in the home.
Bogdan and let's name it new file dot txt like so.
And of course owner of this file will be now root user.
Let's verify that.
Yes, here it is.
Root is owner of this file and here are permissions for this file.
Only owner of this file is able to write this file to modify it.
Great.
Now, let me demonstrate you how you are able to modify permissions for this particular new file dot
txt and recap that if you will try to write this file under other user.
For example.
Bogdan you will definitely get an error file is not writable because of those permissions.
It is not possible to write or execute this file by any other user that doesn't belong to root group.
Before modifying permissions, let me explain you how permissions are actually represented.
Again, there are three different blocks.
Here is the first block with three characters.
Here is the second block, three characters and last block with three characters.
And actually we are able to represent every block with three characters using binary format with zeros
and ones.
And for example, if I want to represent this three characters, I could simply type one, one and zero.
Read, write and not execute.
I could represent those three characters using such combination.
1001 stands for Allow read zero stands for Deny, Write, and this zero stands for Deny execution.
Three different binary numbers, zero and one.
And now let's try to convert those three binary numbers into decimal format.
Do you know how to convert binary number to decimal number?
It is very simple.
In this case we need to add powers of two multiplied by 0 or 1.
Let me show you.
In this case, formula will be following one multiplied by two to power of two plus zero, multiplied
by two to power of one plus zero, multiplied by two to power of zero like so.
And in this case we will get four.
Four is the decimal representation of this binary number 100.
Actually, you are able to use any online converter that will convert binary to decimal for you.
Let's quickly find such kind of converter binary to decimal.
And here let's open up for example, this link binary to decimal converter.
Let's enter here 100 and press convert and I get four decimal number.
Great.
That's how you are able to convert binary numbers to decimal numbers.
Now task for you.
Please try to convert to decimal number this representation, read, write and not execute.
I wish you good luck.
Alright, done.
Let's do that together and let me actually remove this formula and read, write and not execute is actually
represented like one, one and zero and it will be equal to one multiplied to two to power of two plus
one multiplied by two to power of one and plus zero multiplied by two to power of zero like so.
And the result will be actually four plus two equal to six.
Great.
And if they are all ones, I mean, read, write and execute, then result will be equal to seven.
Let me modify it here.
Seven here will be one and here will be one.
And it is actually read, write and execute like so.
So you need to convert this representation into binary representation and afterwards to decimal.
And actually there are most popular combinations like read, dash, dash, read, write, dash and read,
write and execute.
And corresponding decimal numbers are seven stands for read, write and execute.
Let me quickly write it down here.
I'll remove this part.
So read, write and execute.
Stands for seven.
Read, write and not execute.
Stands for six.
And read and not write.
And not execute is actually four.
Like so.
Those are most popular numbers.
Decimal numbers for permissions.
And now let me show you how using this knowledge, we are able to modify permissions for a specific
file.
Let's remove this part.
And here for modification of permissions, we will use command mode like this.
And next, we could supply number as first argument.
And let's type here number, let's say 000.
And here let's type path to the file.
We want to change permissions home work done, new file like this.
Let's press enter.
And now let's list contents of the home work done user.
And now I see following permissions because zero in decimal represents 000 in binary format.
That's why now there are actually empty permissions and we are not able to read, write or execute this
new file dot txt.
Let's now modify permissions to following change mode.
And here will be, let's say, 400.
Press Enter.
Let's verify settings now.
And now I see that it is possible to read this file only by owner of this file.
Great.
Let's modify permissions again.
And now here, I'll set permission 700.
That stands for Read, write and execute for particular user, but no other permissions for other users.
And now let's verify it.
And actually now you see that permissions were changed to read, write and execute.
And color of the file was changed as well.
And the reason for that is that I have just made this file executable and all executable files in Bash
Shell will be marked with green color like you see here.
Great.
Now task for you.
Please modify permissions for this file and make it executable.
Writable and readable for owner and readable and executable for remaining users in group and for other
users in other groups.
All right.
First, let's try to write permissions.
We want to assign to this new file in text format.
So permissions will be following, read, write, execute by owner, read, not write and execute by
all other users in group and read.
Not write and execute by all remaining users in other groups.
And we already know that this section is represented by number seven in decimal format.
We have just used this number here and we have not yet calculated this section and if represent this
section in binary format, I'll get 101 where this one is four in decimal and this one is one in decimal
four plus one.
Four plus one is equal to five, and that is the permission for all other users in group and for all
other users in other groups.
It means that final command will be 755 like this.
Let's verify that.
Let's list files and folders here and now.
I see.
Desired result.
Now this new file dot txt is writable, readable and executable by owner and only readable and executable
by all remaining users.
And if you want to set full permissions, you need to type here.
Seven, seven, seven.
Like so.
Great.
That's how you're able to modify permissions using decimal representation.
Also, you are able to add some permissions and to remove some permissions using following syntax.
Let me show you.
Let's go back to this command.
And here, instead of 3/7, I'll write following dash x.
Let's press enter.
And now let's verify what was changed for permissions.
And now I see that execution permission was removed from all three parts.
Here, here and here.
This what this minus X does, it has removed execution permissions for particular file.
All right.
Let's try to go back to this command.
And instead of minus x, let's use plus x like so.
And let's have a look again at settings.
And now I see that X was added again everywhere.
All right.
You are also able to remove or add some permissions for particular groups.
For example, if you want to remove execution permission only for group, you could use following command.
Let's go back here and here will be J then will be minus and x j minus x for group, remove execution
permission.
Let's verify that.
And now I see that x was removed here in group part.
All right, let's now try to remove also read access for group users and here will be J minus R.
Let's try that list.
And now I see that R was removed here as well for group users.
That's how you could very quickly add or remove some permissions if you want to.
But I personally usually use decimal numbers like seven, seven, 7 or 7 zero 0 or 7 five five that
are most commonly used.
All right.
That's all for permissions.
And that's how you are able to modify permissions for specific files.
And actually now we see that this new file dot txt is writable and executable by all users.
And let's actually now quickly verify that.
Let's change user to Bogdan list files here.
I see new file dot txt here in this list.
And now let's try to modify it.
Nano new file dot txt.
And yes, I'm able to modify it because now permissions allow it.
That's what permissions do and that's how you are able to modify permissions.
And that's what actually will be changed when you modify permissions.
But my personal recommendation to you is to be very careful with permissions and not assign very broad
permissions that will make some files readable, writable and executable by all users in the systems.
Please assign only necessary permissions that you really need.
All right.
That's all for this lecture.
And in the next one, I'll tell you how to create executable shell script using terminal.
I'll see you in the next lecture.
Bye bye.