Now all good things comes in three, at least that's what I have heard
anyway. Now we have our three permissions, read,
write, and execute, but we also have three objects.
We can assign permissions through to the user. Permissions are
granted then to the user owner of the file.
If you do match then on the user ID of the file owner,
no other permissions are going to be applied.
Permissions are not cumulative in Linux.
Next up, we have the group.
So if you belong to a group who is the current group owner of the file,
then you can pick up on the permissions granted through to the
group, so long as you're not the owner of the file.
Finally,
we have others. Specifically, this is others and not everyone. Others
refer to those people who don't match on the user, who don't match on the
group ID, and then you're picked up by others.
So this then is a catch all for everybody who's not the user or the group.
Got that? Great! Let's move on.
When setting our file permissions, we use the chmod, the change mode command.
We can also use the option ‑v, which is quite good,
especially in the demonstrations, as that verbose output is going
to show me the permissions before and what they are changing to.
When we're setting up permissions with chmod, we can use either the
octal or symbolic notations.
So we can go ahead and create ourselves a new file.
We can go through, of course, and then list the permissions on that file.
Depending on what our umask is currently set to, then our permissions may
appear something similar to this. With this, that our umask would be 2,
removing the w or write permission from others.
As we go through and set our permissions, we can set it, as I say,
octally, using 666.
This will set read/write, read/write, read/write all the way through.
When we're setting our permissions with the octal notation,
we have to set the complete block.
Whereas, if we choose to use the symbolic notation,
we can just go through and say others plus w. It's really good because I
don't have to know what the current permissions are.
I just want to make sure that others have got the write permissions.
Now a lot of times, people are going to look at you using the
symbolic permissions, and they're going to go, ah bless.
They haven't quite gathered the idea of using numbers, so they're
still using symbols. It's often thought of as being an easier way
to administer your permissions,
but not necessarily the best way, but that's complete and utter rubbish.
One of the things I can show you is that there are more options and advanced
options available to you if you use those ah bless symbols.
So let's go through and set our umask so we're not
assigning permissions through to others.
We can go through and create ourselves a directory structure.
So here we're creating the top‑level directory, upper,
with two subdirectories, dir1 and dir2.
We can create a file in both dir1 and dir2.
Using our good friend uppercase R when using ls ‑l, we
can recursively list our permissions.
So this is going to show us the permissions that we have set. But
knowing that we have configured a umask of 007,
we know we are removing all permissions from others.
If I use chmod ‑vR recursively, and then we can go through and
say all+X. Now there's a new one, uppercase X.
Where did that come from?
Well, the uppercase X will only set the execute
permission for the designated object.
Here, we're looking at all objects if, and it is a big if, execute
is already set for at least one other object.
Now, of course,
for us we're going to find that execute is set on the
directories for the user and the group, but it's not set on our files.
So this becomes an easy way that we can configure the execute permissions
for those people that don't have it on our directories,
but not on the files unless execute is already independently set on those files.
Now the other thing is a misunderstanding that often occurs
between using, let's say, just +X and all+X, a+X.
So again, if I go through and set my umask to 7, it may already be set to 7,
but we can make sure that it is definitely set to 7. Create another new file.
We can check the permissions on that file.
We know there are going to be no permissions granted through to others.
And we can go through then and take a look at when we use +X. When
we use +X without notifying the object that we want to be working
with, a lot of people think that it does apply to all because we
use this all of the time.
We want to add execute through to a script, so we go +X,
and it appears to assign to all objects.
The reason why it appears to assign to all objects is the very nature
of that default umask, which is only removing the write permission.
Here, we're removing all permissions, so execute can only be set if
it's allowed through the umask.
If we tried it again using chmod all+X,
we're going to be able to see that the permissions are set. So we
can see there's a lot to learn about chmod.
We're going to go out to our command line now and take a look at working with permissions and ownership at the command line.