We're going to take a look at our first demonstration
where we're going to see how we can use the chmod command
to set our standard permissions.
So when you're ready,
we shall begin. And here we are at the glorious command line of Ubuntu 20.04.
And the first thing that we're going to do is just set our umask back to a
more standard. It doesn't really matter what we've set it to,
but at least we know we are removing now the write permission from others.
So with that done, we can go through and say create ourselves a new file.
The touch command will do this for you.
If the file does exist though, it will just change to the timestamps.
So I'm going to go through and touch new_file. Of course, touching the
file doesn't show me the permissions, so let's go through and double
check. When I go through and do an ls ‑l and escape and dot, we can
list then the permissions. And as we know now that a umask of 2 is
removing write from others.
With that set, let's say I want to set my permissions
now, so I can go through and do a chmod.
If I don't include the option ‑v, we are not going
to see our permissions being set.
If I just want to make sure that everybody has the write permission,
then I can go through and go a+w.
So I can go through and say,
well I don't care what the current permissions are, but just make sure that
the write permission is included for each object. And we can go through and
run and do this for our new file. Now of course, it's not going to display
the permission because I didn't use the ‑v. When we're running
demonstrations, often it's very good to use the option ‑v. If I go back and
then go through and run the same command again, obviously no changes will
be necessary.
So we can see then the permissions have been retained, but
it's showing me a 666, a read/write,
read/write. and read/write. Now, it's not important to use a ‑v, but
I think it helps in these demonstrations so you can see what is
being set and how those permissions are changing both octally and in
the symbolic format. If I wanted to set the permissions on
everything to a known value,
I'm probably going to go through and use the numeric notation.
It's much easier even though I have to do a few calculations in my head.
But let's say that I want this to be read, write, and executable to the
user, readable by the group, and no permissions for others, then this
becomes a very easy way. With the ‑v option on,
we can see then the permissions changing what they
were and what they changed to.
So we can see everything has been set the way that we wanted.
So if I'm setting the complete block,
I'm going to probably use the octal notation.
But the problem is with the octal notation is I have to
know what I need for the complete block.
Whereas, if I just want to change permissions,
whether I'm adding, setting or removing permissions,
I can then go through quite easily.
Let's say now that we want to make sure that others have got read. I can go
through and put o+r. Plus is adding the permission if it doesn't exist. It won't
matter, it doesn't error if the plus is there. We're specifying a desired state.
So we can see then as we've run through,
we've gone from 740 to 744.
If we want to run through and make sure, let's say, that the group
and others have read and write, we can put equals read and write,
and I can put the two objects, go, together. So we can see now that
we've changed from 744 to 766.
If I need to make sure that everyone has the execute permission,
we can then go through and use a+X. More on how we set for everyone later.
But for the moment, let's go through and put a+X, so all+X.
If we want to make sure that nobody has the execute permission, we can use a‑X.
And again, without regard to the current permissions, if I just
want to make sure that this is private through to just the user,
we can go through, and let's say group and others equals and
then set no permissions.
And again, we can see there that we changed to our 600 permissions.
So our symbols can be really good.
The big advantage with the symbols is I don't have to know what
the current block is to make the adjustments.
I can set the desired state. I can use that using the plus, minus
or the equals symbol, and I can do that for the user group or others, or to include all, I just use a.