File permissions in this lesson, we will learn how you could change the permissions of your files and
directories this way you are protecting your environment, your files and your directories from being
viewed by other users are being deleted by other users.
Unix is a multi-user system, every file and directory in your account can be protected from or made
accessible to other users by changing its access permissions, every user has a responsibility for controlling
access to their files.
Permissions for a file or directory may be restricted to buy its types.
There are three types of permissions read, write and execute.
I'm sure you know, read and write.
What does it mean to execute?
If it's a program, if it's if a file itself is a script or a program, it has an X permission, which
is executable, not everybody is allowed to run a certain permission.
So if a user is allowed to run a program, they would have an executable permissions to it.
E permission, which is read in executable, can be controlled at three different levels, at a user
level, which is yourself at a group level, can be people in the same project or group or a same department
or others like everyone else.
File or director permission can be displayed by running Ellis minus L Command.
So you will see here at the bottom, you'll see read X, the first bit shows that it's.
It's a file the the the next three bit shows it has read right and executed with permission by the user,
the second three bits are for the group and there three bids are for the others command to change.
The mission is change mod.
A lot of times it's also referred to as chmod.
So let's look at our Linux machine, so this way I'll better explain to you how permission works.
Again, the first step you always do is to check who you are.
You are yourself which director you are in and you are in your home directory, and when you do else,
this command will show you documents and folders and files, but it's not going to show you the details,
whether it's a directory, what permission it has or what the size of it.
So what's the option we use?
I'm sure you know this by that and by now, Alice, minus L or L tr whichever you prefer.
So when you do list minus L, you see the listing of all the files with all its details.
Now let's pick one file.
Let's pick.
We'll pick Gerri, we also use the option.
Plus minus El.
Jerry here, you'll see.
The first bit.
Right here, Dasch, this one refers to as it's a file, the second three bits referred to as read,
write and execute.
Now, this shows the user I ASOL, which is myself who created this file, has only read and write permissions.
I do not have executable permission.
It means I this file is not a script.
That's why it does not have executable.
There was a script that it would have access to it.
So I have me myself as I absol has a right and a right to read the file and write to write to it.
The second group who owns it, who has a permission is right here is.
R. W..
And again, Dash, which means the group, which is the group itself, is also I have also have RW and
Desch and the last one is other these lasy permissions.
Is that the others are can only read this while they cannot write to it or they cannot delete to it.
So these are the permissions at the level of user group and others.
Now let's take the command to change these file permission.
What's the command to change the file system is change mod again, every time you are learning a new
command, I will highly recommend you that after the lesson you run man and see D they followed by the
command name.
This will give you all the details about the command, what it does, what options it has with the commands
are used for and so on.
So I'm going to use S.H. MODIS.
Command and I what I wanted to do right now is I want to have the group right here, these three, but
I want this group to not have the w the right permission.
So I will do as G as a group minus W and the finally Jerry.
So what I'm telling the operating system to do is remove the right permissions from the file name Jerry.
Again, this shows that I have a command right here and these are my options and these are my arguments.
So once I execute that.
He'll give me my prompt back and when I do less.
Minus LTA, minus L, Jerry, and you will see right here now, there is no right permission.
So anyone in the group of can cannot write to this far, they can still read it, but they cannot write
to it.
Now I want to remove their read permission from everyone.
So the command to do that is S.H. Amadi.
And if you want to do for everyone, the Jews use a as for all minus.
Ah, and which file are you working on, you've working on Cherry, so you hit enter and you do X minus
Alti or or just in cherry.
You will see no one has read permissions.
Now we only have the right permission by the user.
I have so I want to remove that right permission as well.
So what do see mode and now which option am I going to use?
I'm going to use you as user.
Remember, we had three different groups, three different ways we could change it right here.
Each permission can be controlled at three levels.
You G and O.
So I'm going to use you as because you as myself, minus W Jerry.
However, fight again, you do this myself, Gerry, and there you go now you could tell by looking
at this file that it has no permission.
So even myself, if I wanted to delete this file, I cannot delete this file.
Let's look at R.M. to remove a file.
Gerry.
It will say remove my your empty while it is giving me the warning sign that you this is right, protected
if I say yes than ever and more because since I'm the owner, actually, but it does give me a warning
sign so I don't want to remove it.
I'll just say no.
And then if I wanted to read a file to read a file, you could use the command cat, which I will cover
later on.
But for this lesson, I'll just tell you, Jerry, we could do the read and I will see it says permission
denied.
Why is that?
Because I don't even have a read permission to read the file.
So I wanted to give back all the access that all the permissions that I had at the beginning.
Right here is the file.
And I wanted to give back all the permissions.
So let's start with the first user, Sciascia Modise, and the user is you and I wanted to give plus
because I'm adding permission and I want to give Reed and W.
And Jerry.
Let's see if it has the permission that I want.
Yes, it has it now.
The user has it now.
I wanted to give the group the same thing.
So what do you do, by the way?
You could run up Arrow.
To go back to the last command that you typed, so this in this case will just to replace you with G
hit enter.
Let's check it again.
And there you go, we, the user has it rewrite the group, has it read right, but others don't have
anything.
Well, when we created the file, others had to read permission.
So I wanted to assign to others as well.
So the command to do it is changed.
Mod others plus read Jerry.
Let's try it again to see if it worked and it did.
Now we got all the permissions back.
Now this same command works and a directory works and a link and works and a file you could use on anyone.
So these are the three permissions that you can see.
You have this permission column, the first column.
In your El's minus output, this would tell you what kind of permissions you have now, what if a directory
has this executable right here?
Does that mean the directory is a script?
No.
The reason it means X here is because you could KDDI into that directory.
That's where you have X in the directories.
So if I have this directory called Seidenfeld, I could do KDDI sign Steinfeld and log into I could
actually get into the same file directory.
Now let's go one step back and do a less minus L tr again.
And now I don't.
I want to take away the permissions to for everyone to go into that directory.
So what I do is change mod.
I want everyone so a minus executable Sinovel.
So now when you do list myself here you'll see this directory has read right.
But no executable rewrite, no executable read write.
No read, no executable.
No right.
So can I add KDDI into the directory now.
I don't know.
Let's see Cricinfo.
Permission denied.
All right, why?
Because we don't have executable right to that directory.
We have to have an executable right to copy into that directory.
So let's assign the permission back.
All plus X Sinophile.
And this check again and you will see the sign at the bottom now has executable, executable and executable.
This is how you could protect your files and directories from being manipulated or being deleted even
by accident.
File ownership in this lesson, we will cover how files and directories are owned and how we could change
the ownership of those files and directories.
So the file ownerships are created on user level and a group level.
There are two owners of a file or directory, a user, the one who creates the file or directory, and
the second one is a group.
The user, the group that belongs to if you are if you belong to two different group and permission
applies that the second group has agreed permissions, or you could delete a file, a directory, as
long as you are in that group, then you will have the right.
Command to change file ownership is change own, which is also known as chain owned and change group
CBH Group change on changes.
The ownership of a file change group changes the group ownership of a file.
Recursive ownership change option, if you are using an option with change own or change group with
minus uppercase, or it will not only change that directory, but also all the files and directories
within that parent directory.
If you look at the example of windows that say we have this folder called videos and when I click.
When I do right click and go to properties, you'll see that under security, this file is owned by
the systems and I afsal an administrator.
So you see these two people here.
These are the group and the single user.
One person here is just the user.
And again, the system is a group.
So group system and administrator on this file, a folder called Video.
And the user who created their folder is I have TSOL and you see at the bottom it tells you whether
that user has read, write or secure permission.
You can see right here it has all the permission that we talked about.
In our Linux machine when we log into our Linux machine.
Again, the first thing we do is see who we are, so we are ourself, see what files are directories
we have.
These are all the listing of files and directories we have now here.
And the first, second and here, the third column, the third column tells you who owns this file.
Let's say we go to Lisa.
We created this file, Lisa.
And the person who owns this file, Lisa, is the user I afsal or yourself yourself.
In this case.
The fourth column right here is the group name.
And this case is I afsal again, because I am part of my own group.
I belong to my own group.
I could change that to a different group.
But since I'm a regular user, not a super user, I won't be able to change that permission to any other
group.
The only person or the only account that could change that ownership is route.
So let's become route Sue.
Dash.
Once you log in, you do TWD and here it will bring you into cheroot.
Now remember, you are not in your home directory.
You are in rude territory because you are rude right now.
So I want you to go to your home directory, which is to remember slash home.
And slash your username.
It will take you to your home directory, you could just hope to confirm and duelist Manaslu TIAR to
confirm and at the time that these are your directories and files, if you wanted to change the permission
of Lesa and you wanted to change it from yourself and you wanted to have this owned by route, which
you will do as change your.
And you specify the name of the user you want to change to.
And the name of the file, Lisa.
And then when you do a less minor sell to your ear, you will see why here.
The file is now owned by a route you could also do just to be more specific, so you don't see all of
the files you do unless mysel, Lisa, and you'll see here now the file is owned by a route.
You could do the same thing when you do CBH Group, which is to change the group, you could do the
group.
Also, there was another group called Route and you could do this again.
And you were fired, and now you'll see this fire, Lisa, is owned by a root and and the group who
owns this file is also root.
Now, what happens when you become yourself again?
How do you get out of this root account?
You just simply type exit.
You are logged out and just confirm who you are.
You are yourself with territory, you are in your new home directory dweller's mysel tr and you see.
There was this vile.
Lisa, now what happens if you try to delete this file?
Let's see our friend Lisa.
It will tell you remove right protective of empty file.
If you say yes and do this myself here.
There you go.
It is gone.
The reason it is gone now why is because when you go one step back to your home directory, so your
home is right now is slash home, slash yourself.
And when you go one step back.
You are in just slash home and do less mysel here, you will see the eye of subdirectory, which is
your home directory, has the permission of yourself to read, write and execute, meaning anything
inside of the directory.
You can read.
You can write.
And you could execute.
So regardless if whoever puts the file in, whoever owns the file.
Or who whichever group owns that you could go ahead and still delete it now if you try to create a file
in, let's say, Etsy.
And you go touch.
Test fire.
It would tell you permission denied because you do not have permission to write to this file.
How do you check that you do Ellis Linesville slash?
You could do that or you could simply go to city slash and do a less mysel, and you'll see here's a
list of all the directories that are inside of.
And the one we were trying to go to is at.
If you notice, the Etsy is owned by route and the group is owned by a route as well.
Now, the route has the permission to write to it.
But what about the people who are in route group?
They don't have a permission to write it.
What about everybody else?
They don't have a permission to write to it.
So that is why you cannot create a file in Etsy.
So let's let's see if you become rude again.
OK, and now you go to ETSI.
And you create a file touch test, one, two, three is verified, a A.l tr.
You see the bottom as your file.
Now, another way, what you could do is while we're working on this, you can minimize this window
and you could open another window by right.
Clicking and clear open terminal.
So this way, we have a regular account, which is our account and the route account.
So this way we don't have to exit out of the account.
So we are.
We are, as always, to actually we are in we are in session and we created the file in ETSI, right,
as a rule.
So let's go to ETSI and let's see.
Let's Maricel TR and now we're going to try to remove this file test.
One, two, three.
And it's going to say remove, right, protected, it's just a warning usage.
Yes.
And it's still says permission denied.
Now, why it's saying permission denied.
Again, you go to a slash and you do X minus L, and you will see right here, that's the Etsy directory.
And it'll tell you right here, the group three do not have my permission and the other three bits do
not have write permission as well.
So that's how you change these user files.
Ownership and group ownership of the two commands that we learn is change.
Ownership, which is C, H, o and W o, w, n and the second one as change group.
So again, really want you to do a man on each command.
And go over the description, the different option it has.
Same thing you do with the with a second command as well.
And also I want you to practice this command by changing the mission only in your home directory.
So your home directory is.
Slash home, slash yourself, and you could try chaining permission to one of the directory, like create
a new file.
Don't touch the files that you created and just the permission and test file.
Create this file and just practice your change ownership and change group command on this file and see
how you could change it.