Permissions tell us what a user or a group can do with a file or a directory.
Can they read the file? Can they execute it? Can they access the directory?
If they can't execute the file?
How can we change the permissions so they can do so.
These are all important questions that you'll need to be able to answer.
And I'm going to give you all the secrets right now.
Alrighty, it is demo time.
I've got the terminal opened up on my local machine and I am in a demo directory
that I've created. And in here I have file 1.txt, file 2.txt,
and then script, that's called the runme.
Let's first start off by listing the permissions that
these files have. We can use the LS command, which is lists,
which we used to previously to list them out.
But now we can use the dash L option here that stands for log,
and this will provide us a more detailed listing.
There's a bunch of columns here,
who's the owner of the file or a directory.
And then who is the group owner of the file or directory.
And then, uh, the time is created and the name,
but the column that matters to us for this demo is this first one with a bunch
of what seems to be random characters.
So we have a set of 10 characters here. This first one is going to tell us,
what is this? Is this a file? Is, is a directory? Uh,
yeah, just tell me what it is. So right now we have this dash,
which stands for regular file.
Typically you'll see there a dash or a D that stands for directory.
So if I were to make a directory inside of here, call it demo2,
and then I'll list it out again. You see here,
we have a D because that's a directory, you might see a,
an L which stands for symbolic link or C,
which stands for character special. Uh,
but typically it'll be regular file demo or symbolic link.
And now we see let's take a look at this file one.txt.
So we already know that the stands for, Hey, this is a file. Next.
We have nine characters and these are actually sort of split into
three groups of three.
So we have R which stands for read w which stands for write.
And then we have a dash whenever we have a dash.
This means that this specific permission has not been granted.
So what is this saying? So if we have in the first three characters,
this play is for the user.
The next three are the permissions for the group.
And the next three are permissions for people who aren't the user and who do not
belong to the group. So others. So the user has read,
write and no execute. Remember that the dash means no permission.
The group has read, write no execute, and others only have read,
and we can see the others are pretty similar except for this file too.
Doesn't have any permissions at all for the other call, right? Okay.
Let's look at how we can modify it permissions
at the moment. I can't actually execute this run me script,
even though I own it.
You can tell who owns the file by whichever value is in this column here and my
case it's me. But if I try to run this script,
I'm going to get permission denied. As you can see,
there's no execute permission in here because there's no X value specifically.
There's no X value in the first three characters because this remember the first
three characters are assigned to these.
We can change this using the chmod or change mode, um,
command. Then we can say to the user,
give them execute permissions. So you plus X,
if you wanted it to be the group you would use G you want it to be assigned to
others who would use though. And then I'll provide the name of the file.
Keep in mind that this command can only be used by the person who owns the file
or the root user.
So now if I do plus dash L once more,
you can see that we now have an X, in here, place,
where there used to be a dash. So now if I do run,
we can see, we can actually execute this. Fantastic.
But what if we wanted to assign a permission to everyone?
So we want everyone to be able to run the script. Well,
we can do chmod plus X here,
and then the file. And if we do LS l here,
we see that we have an X in each set now.
But what if we want to remove that?
Do we really want everyone to be able to execute this? I don't think so.
We'll do chmod minus X and then run. There we go.
Fantastic. Let's do a few more here.
Let's allow the others to read files too.
So we can do chmod others,
plus read file2.txt.
See, now let's list that out and you see,
we now have r here and let's
allow others to write to file1. Let's do chmod, others
plus w and we'll do file1.txt
smart list. Yeah. And then you get the idea. We can add permissions this way.
We can move permissions this way.
Just be mindful that you should only use this command when you are absolutely
sure about which permissions you are changing.
You might end up removing a permission that is for a process to work,
or you might end up adding a permission that will reduce the security of your
system.
And that is it for the demo. We reviewed how to view permissions, change them,
remove them.
And we understand the responsibility of using the change mode command. Alrighty,
Cloud Gurus. That's it for this episode of ACG Fundamentals,
go on and check out the permissions of some files you have on your machine,
but be careful, let us know how it went in the comments of this video.
Keep being awesome. And I will see you in the next one.