[No audio]
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 second group has read
permissions, or you could delete a file or
directory, as long as you are in that group, then
you will have the right. Command to change file
ownership is change owned, which is also known as
chown and change group, chgrp. chown
changes the ownership of a file, chgrp
changes the group ownership of a file. Recursive
ownership change option. If you are using an
option with chown or chgrp with -R,
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, let's say we have this folder
called Videos, and when I click, when I do right
click and go to Properties, we'll see that under
Security, this file is owned by the SYSTEM, and
iafzal, and Administrators. 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 own this file or folder called
Videos. And the user who created that folder is iafzal.
And you see at the bottom, it tells you
whether that user has read, write, executable
permission, you can see right here, it has all the
permissions that we talked about. In our Linux
machine when we log into our Linux machine,
[No audio]
again, the first thing we do is see who we are. So
we are iafzal. See what files or 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 iafzal,
or yourself, yourself in this case. The fourth
column right here is the group name in this case
is iafzal 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 root, so let's become root su-.
[No audio]
Once you log in, you do pwd and here it will bring
you into /root. Now remember you are not in
your home directory, you are in root directory
because you are root right now. So I want you to
go to your home directory, which is, if you remember
slash home and slash your username. It will take
you to your home directory. You could just do pwd
to confirm and do ls -ltr to confirm another
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 it
to have this owned by root, what you will do is
chown and if you specify the name of the user
you want to change to and the name of the file,
lisa and then when you do ls -ltr, there you
will see right here,
[No audio]
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 ls -l lisa,
and you will see here now the file is owned by
root. You could do the same thing when you do chgrp which is to
change the group, you could do the
group also, there was another group called root, and
you could do lisa again, and go verify it. And now
you will see this file lisa is owned by root, and
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, yourself, which directory
you are in, your new home directory, do ls -ltr,
and you see, there is this file lisa. Now what
happens if you try to delete this file? Let's see.
rm lisa. It will tell you remove write protected
regular of empty file. If you say yes, and do ls
minus ltr, 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,
[No audio]
you are in just slash home and do ls -l. Here
you will see the iafzal directory, which is your
home directory, has the permission of yourself to
read, write, and execute, meaning anything inside
of the directory you could read, you could write,
and then you could execute. So regardless if
whoever puts the file in, whoever owns the file, or
who whichever groups owns it, you could go ahead
and still delete it. Now, if you try to create a
file in, let's say, etc, and you go touch test
[No audio]
and you call touch
[No audio]
testfile. It will tell you Permission denied because
you do not have permission to write to this file.
How do you check that, you do ls -l /. You
could do that, or you could simply go to cd slash
and do ls -l. 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 etc. If you
notice here, etc is owned by root and the group
is owned by root as well. Now the root has the
permission to write to it. But what about the
people who are in roots group, they don't have
permission to write to 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 etc.
So let's say if you become root again.
[No audio]
Okay, and now you go to etc, and you create a file
touch test123, just verify it, ls -ltr. You
see at the bottom is your file. Now another way
what you could do is while we are working on this,
you could 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 here, iafzal, which directory we are in
we are in slash home and we created the file in
etc right as a root. So let's go to etc, and
let's see ls -ltr, and now we're going to
try to remove this file test123, and it's gonna
say remove 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 a cd slash name, and you do ls -l.
And you will see right here, that says etc
directory, and it tells you right here, that
group, three bits do 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 ownerships
So the two commands that we learned is changed
ownership, which is chonw, sorry, own, and
the second one is changed group, chgrp. So again, really
want you to do a man on each command and go over
the description, the different options, it has.
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 home
slash yourself and you could try changing
permission to one of the directory like create a
new file, don't touch the file that you created
and just the permission, testfile, create this
file and just practice your chown and
chgrp command on this file and see how you could change it.
[No audio]