So, yes, we're going to dive out and find that elusive command line,
and we're going to look at how we can set some of our special permissions.
We really want to look at setting them and viewing them.
We can list or view those permissions with ls ‑l,
and obviously we can use the find command,
as we've seen within the demonstration,
to be able to locate files or those directories with those special permissions.
Come on, let's find that command line.
Oh, wouldn't you know,
we found that command line, and we're going to start our learning.
If you've got your system ready,
I'm using Red Hat Enterprise Linux 8, and we set this up in our initial
course using essential tools in RHEL 8. Let's go through and create
ourselves a directory. So we're going to use mkdir ‑p so it creates the
parent directory. We're in my home directory, I can see that by the
tilde within the prompt,
and we're going to go through and call it, let's say perms.
And then we're going to have dir as our suffix, and we can
go through, or prefix rather,
and we can have 1 through to 4. So we're creating then those
directories, and I can use the tree command inside of perms
to show what we have created.
So that's all well and good.
The other thing as well with the mkdir ‑p is it's quite safe within scripts.
I can run it multiple times,
and it won't complain that the directories already
exist, it just doesn't do anything.
So we can start building in this idempotency that they talk so
much of within Salt and Puppet and Ansible.
We can build it into our command if we've got the correct options available.
Now when we go through and start setting up permissions,
we can use the chmod command. Within these demonstrations, I
like to use chmod ‑v so we get to see the permissions that
they're changing from and changing to.
I'm going to then put 1, so the sticky bit is
configured, and then 777 so we've got, read,
write, and execute all the way through for our user, group, and others.
And we can then go through and do this on our perms and dir1.
So we can see then the permissions have changed from 0775 to
1777. But look at the permissions.
We can see that there is nowhere to display the symbol for our
special permissions, so it goes in the others block. A lowercase t
indicates the execute permission is set, and uppercase T, as we'll
see later, will then show you that the execute permission is not set.
So the sticky bit is set.
The sticky bit is used to control deletions, and we'll see that working.
As we then go through and start looking at setting other permissions, we
can go through and set the group ID bit used to control ownership, and
we'll do this on dir2. So we can see now then that shows in the group
block. We've got read, write, and s, or set group ID bit, set on this one.
When we go through and look for dir3, we can combine some permissions together.
So we put a value of 3, that's going to be 1 for the sticky bit and 2 for
the group ID bit. And when we look at then the way the permissions are
showing now, we've got our group permissions of read,
write, and s, and our other permissions of read,
write, and t, again, the lowercase indicating that the execute
permission is set for both the group and others, but it's masked by
the special permission. Now hopefully you're keeping up with me, and
you're able to understand what's going on, but let's go through and
just modify this a little bit.
Still working with dir3, let's go through and set our
permissions to 1770 and see what happens.
We're setting the sticky bit, and we're then going through and
making sure that others don't have permissions.
Now we can see that it changed, and we maintained everything. We even
kept the group ID bit, we'd have to explicitly go through and remove
that. But look at the uppercase T now. We're no longer masking the
execute permission, because it's not set. If we go through and set
this independently,
setting it back to the permissions that we had for dir3,
we're going to need this for searching,
but then going to dir4 and then setting 1770, we can see where the
group ID bit is not set, we do just get the sticky bit, but, again,
it's showing in the uppercase format.
We are no longer hiding the execute permission, because it's not set.
And, of course,
we can also go through and see this by doing a long listing of our perms
directory, and we can see then the resulting permissions that we've got
from the different scenarios that we tried out.
Remember, the uppercase special character is indicating that
it's not masking the execute permission.
Lowercase is then representing that we are hiding the
execute permission, and it is set.
Now, if you know me, you know I like the find command,
and we'll look at some of the power that we have behind the find
command. Looking within our perms directory, so that's our base of
our search, we can look only for directory,
so ‑type equals d or ‑type d,
as opposed to f if we wanted to look for regular files or l for
links. We can then go through and look for our permissions, so ‑perm.
And where we go through and put our forward slash, we're looking
where either permissions are set. So we can go through and say where
the group ID bit is set or where the sticky bit, and it's a
comma‑separated list, and,
of course then, that's on all four of our directories. Now,
clearing our screen, so just moving back to the top so it's clear,
we can then go through and use the dash. Where we use the dash,
we're then saying where both are set.
So we're looking for the group ID bit and the sticky
bit being set, and, of course,
that's only on dir3, where the group ID bit is set and the
other permissions have the sticky bit.
If we go through and start looking at, say,
just for the sticky bit, we can see the sticky bit is set on 1, 3, and 4.
But remember, where I use the forward slash, we are
looking for either permission being set.
So if I go o=tw, we then get all four directories, because either
the sticky bit is set or the write permission is set in the
directory, so we're seeing all four directories.
If we wanted to make sure that we're only seeing where the sticky bit
is set and where others have the write permission,
just use the dash, so ‑o, others, equals both the sticky bit and
writeable permission, so show me directories that are world writable and
have the sticky bit set, and it's dir1 and dir.
As you do more with find,
you're going to find it's a really invaluable tool, and you're going
to be wanting to learn more and more about it, so please play around with this and get some great practice.