File ownership and this lesson we will Khowar how files and directories are owned and how we could change
the ownership of those files and directories.
So the file ownership's 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 group that belongs to if you are if you belong to a different
group and permission applies to sick the second group has a read permissions or you can delete a file
or directory as long as you in that group then you would have the right command to change file ownership
as Change own which is also known as change.
And Change Group CAGR.
P change.
Owen changes the ownership of a file change group changes to 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 man click when
I do right click and go to properties you'll see that under security this file is owned by the systems
and IFCO and administrator.
So you see these two people here.
These are the group and the single user one person here is just a user.
And again the system is a group so group system and administrator own this file a folder called video
and the user who created that folder is I saw.
And you see at the bottom it tells you whether that user has read write or executable permission.
You can see right here it has all of her mission 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 our self.
See what files are is rehab.
These are all the listing of Foz and directories we have now here.
And the first second 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 flier lease is the user.
I have Zaal or yourself yourself in this case the Ford column right here is the group name.
And this case is I have saw 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 root SU dash
once you log in you do PWT.
And here will bring you in to slash route.
Now remember you are not in your home directory you are in route directly because you are route right
now.
So I want you to go to your home directory which is remember slash home and slash your username.
It will take you to your home directory.
You could just do PWT to confirm and do a last minute cell to your to confirm in the time that these
are your directories and files if you want to change the permission of Lisa and you wanted to change
it from yourself and you want to have this.
Owned by root will do is change your own and you specify the name of the user you want to change to
an the name of the file.
Lisa.
And then when you do this myself to your ear you will see right here
the file is now owned by root.
You could also do just to be more specific so you don't see all of the files.
You do this myself Lisa and you will see here now the file is owned by root.
You could do the same thing when you do see h g r p which is to change the group.
You could do the croup.
Also there was another group called root and you could do this again and verify it.
And now you'll see this file the site is owned by root and the group who owns this file is also root.
Now what happened 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 which directory you are in you are in your home directory do ls my SL TR And you see
this file Lisa.
Now what happens if you try to delete this file.
Let's see.
And Lisa will tell you remove right protective read leave empty file
if you say yes and do this myself.
Here they go.
It is gone.
The reason it is gone now.
Why is because you go one step back to your home directory so your home is right now.
Is slash homes like yourself.
And then you go one step back.
You are in just slash home and do less minus.
Here you will see the I have self-direct tree which is your home directory has the permission of yourself
to read or write and execute.
Meaning anything inside of the directory you read.
You can write.
And then you could execute.
So regardless if whoever puts the file in whoever owns the file or do whichever groups owns it you could
go ahead and still delete it.
Now if you tried to create a file in let's say Etsy
and you go touch test file it would tell you permission denied because you do not have permission to
write to this file.
How do you check that.
You do this NSL slash.
You could do that or you could simply go to CDs slash and do less minus.
And you'll see here's a list of all the directories that are inside of slash and the one we were trying
to go to is see if you notice Etsy is owned by root and the group is owned by root as well.
Now the route has the permission to write to it.
But what about the people who are in Rootes 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 we become rude again.
OK and now you go to ETSI and you create a file touch test one two three verify this myself or you see
at the bottom a file.
Now another way what you could do is while you're working on this you can minimize this window and you
could open another window by right clicking and create open terminal.
So this way we have a regular account which is our account and the root account.
So this way we don't have to exit out of all accounts so we are your solvers actually we are in your
home and we created the file in ETSI right as a root.
So let's go at c and let's see let's madness out here.
And now we're going to try to remove this fall test.
One two three and it's going to say move right protected it's just a warning.
Usage Yes.
And it still says permission denied.
Now why it's saying permission denied.
Again you go to at CD slash and you do ls minus L and you'll see it right here.
That's the C directory and it's tell you right here.
The group rebates to not have write permission.
And the other three bits do not have the right permission as well.
So that's how you change the user of the files.
Ownership and group ownership of the two commands that we learn as change ownership which is C H O and
W O W and the second one as change group.
So I again really want you to do a man on each command.
And go or the description and the different option.
It has the same thing you do with the second command as well.
And also I want you to practice this command by changing the permission only in your home directory
so your home directory is slash Homeside yourself and you could try changing permission to one directory
like create a new file don't touch the files that you created and just the permission test file create
this file and just practice your change ownership and change group command on this file.
See how you change it.