So this video is about managing of basic Linux permissions.
First thing to understand is file ownership.
Permissions are assigned to user group and others, and these are the file owners.
And by default the user who creates a file becomes a user owner and the
primary group of that user becomes group owner and everybody else belongs to others.
This is also referred to as ugo, which stands for user group and others.
Standard Linux permissions allow for one user owner and one group owner for each file. And you
can use shown to change user ownership like shown Anna Myfal or Chownanna SILS on data sils
which would set the user owner as well as the group owner at the same time.
The chgrp command is used to change group ownership only. So chgrp sils on
data sils would set the group sils as owner of the data sales directory.
So remember, whenever you are working with basic permissions, you first take care of
ownership and then you are going to take care of the file permission mode.
So chmod is what you use to change this file permission mode.
There are two ways to work with chmod. First there is the absolute mode
and in absolute mode you set permissions to yougo using these octal values.
So chmod 750.
What does that mean? 7 is for user, 5 is for group, 0 is for others, 7
is 4:2:1 and that means that this command is giving a read, write and execute to the
user and it's giving a read and execute to the group and obviously nothing to others.
As an alternative, you can also use a relative mode.
In relative mode you use a command like chmod x which is convenient
to make a script executable. For instance chmod U W Regardless of your
current setting, you are adding the write permission to the file.
Now, as a best practice, I recommend you use absolute mode for
full control and relative mode for quick permission changes. Let me demonstrate.
I'm going to use sudo mkdir Data sales Oh boy, what do
I get here? Well, I get an obvious error. I'm trying to
create directory sales within the directory data that does not work.
That's because data does not exist. But that's an easy fix. Use mkdir P.
Let's get in the data directory and let's use LS L to understand what is going
on there. You can see the sales directory, which is currently owned by user root and
and group root. Why is that? Well, that's because user root has created it and the
primary group of user root is the group root which is revealed by the ID command.
Now, what do we need to do to make sure that members of
the group Sales can write? Well, first sudo chgrp sales to sales.
The first sales is the name of the group. The second sales is the name of the directory.
And LS l is showing that the directory ownership has now been set correctly.
Now I'm going to use chmod g w on Sales.
And of course we need sudo in front of that. That's an example of
relative mode. It works, but it's not very clear. You're probably better off using
sudo chmod770 on sales, and that is setting the permissions in absolute mode.
Now, there's one more thing that I need you to understand, and that is the following.
I'm using sudo touch home anna root file.
Now I'm opening a shell as user anna sudo su minus anna.
And now I'm user Anna and user Anna sees this root file. Now I want you to think about the faul.
Can user Anna delete the file? Yes or no?
Let's analyze Sudo LS l showing the permissions on the file.
File wise, the user has read permissions.
LS ld is showing the permissions on the current directory where
we see that it's Anna's home directory and Anna has write.
And when Anna uses RM on root val, she needs to confirm, but she's definitely capable of doing so.
You know why that is? Because deleting a file requires write permission on the directory.
Anna has write permissions on the home directory home anna because that's the
essence of a home directory and that's how you manage these basic permissions.