In this video, I'll tell you how to manage permissions.
The command that it's all about is chmod, for change mode.
So that is what you use to manage permissions.
There are two ways to use this command, the absolute mode
and the relative mode.
In the absolute mode, you use the numeric representation
of the Yugo permissions.
So 7 is for user, 5 is for group, and 0 is for others.
Now, what is 7?
That's 4 plus 2 plus 1, and 5 is 4 plus 1.
So the result is that user would have read, write, and execute.
Group would have read and execute,
and others would have nothing at all.
There's also the relative mode.
And the relative mode is convenient
if you quickly want to make a script executable,
for instance, chmod plus x.
Regardless of what we currently have,
that would make my script executable.
And you will probably use both of them,
depending on what you want to do.
If you create a directory structure,
it's better to have full control by using absolute mode.
And if you are just making a script executable,
you would use chmod plus x to just assign this execute
permission.
Let me demonstrate how this works.
So I'm getting back to the data directory,
and I want to set some permissions on the data
directory.
But first, I also want to show you special x.
So let me get into the files directory,
and let me use touch file 1 up to 3.
And ls minus l is showing the file permissions.
Permission mode is set to 644.
Do notice the convenient way to create a range of files,
by the way, by using the curly braces 1 dot dot 3.
Now I'm getting back up one level.
Oops.
And I'm going to use chmod to change permissions.
So what am I going to do?
Well, I'm going to use chmod minus r for recursive,
plus x on the files directory.
And now what happens if you look inside the files directory?
As you can see, all files have gotten the execute permission.
That's not what we want.
So I'm going to use chmod minus x on files star,
and repeat my ls minus l on files.
And now we can see that the execute permission is gone.
And let's do it in a better way.
And now use chmod minus r plus uppercase X on files.
And now we can see that the files directory contents,
well, the files did not get the execute permission.
And that's an important one.
There's one more thing that I want
to show you about permissions.
Well, actually, two more things.
Let's first use this chmod command
to set some permissions in absolute mode.
So chmod 750, for instance, on files, which is doing what?
Well, as you can see here, permissions
have been changed to read, write, and execute for the user,
read and execute for the group, and nothing for others as well.
There's one more thing that I want to show you.
I'm going into a home directory.
And there we have the home directory for user Linda.
I'm creating a file, a root file.
ls minus l on root file is showing what is going on.
So in the home directory of Linda,
we have a file with the name root file.
And the permissions are set to 644.
Now I'm going to open a shell as user Linda.
And here's what this demo is all about.
I'm using ls minus l.
And there we can see a root file.
Now the big question is, what if Linda
is going to remove root file?
Is that going to be allowed?
Yes or no?
Take a second to think about it.
Thought about it?
Well, let's try.
And there you can see it worked.
And in case that surprises you, you
need to understand why it works.
Linda is in her home directory.
And Linda in her home directory has write permission.
And deleting a file requires write permission
on the directory that contains the file.
So deleting a file is a directory operation
from a permissions perspective.
And the permissions that you have on the file itself
are not important.
It's all about directory permissions.
And that is why user Linda is allowed to delete the file
here.