Now, it's not just directories where we can set special permissions,
we can set them on executables too.
For example, when we take a look at the password program,
we're able to write, as a standard user in setting our own password,
to the shadow file.
The shadow file is only writeable by the root user.
This is made possible by the set‑user‑ID bit being configured.
This then allows the program to run as the user owner.
Similarly,
with a set‑group‑ID bit, if this is configured on an
executable, it runs as the group owner of the file.
Now we might find this is set as normal on programs
that need to write to a user terminal.
The tty group is configured to have write access through to your terminal,
but there are no members of the group.
Whereas if we look at programs such as write or bsd‑write,
depending on your distribution,
it is configured with the set‑group‑ID bit and is owned by the tty group.
To be able to investigate this,
we can move out to our command line and take a look at how our
set‑user‑ID bit and set‑group‑ID bit work.
And here we are working on our AlmaLinux 8 system,
and when we go through and just take a look at ls ‑l,
we'll do a long listing of our /etc/ and shadow file.
This is where our user passwords are configured.
And we can see in AlmaLinux, and it would be the same on RedHat as well,
we have empty permission blocks.
Now, of course, the root user can always bypass permissions,
but certainly then for a standard user,
we're unable to read or write to the file.
I'm able to list the file because I have permissions to the etc directory,
but I'm unable to even read the file.
If I change this to the cat command and go through and look at
escape and dot bringing up the last argument,
you can see I don't have even permissions to be able to read the file,
yet I can set my own password.
I can only set my password and security is controlled by the program ls ‑l,
let's go through and take at it, usr/ bin/passwd.
Now we can see it's highlighted there in red indicating that
we have got the set‑user‑ID bit configured.
When we execute, we execute as the owner of the file, which is root.
The program itself does all of our security checks,
making sure that I'm only changing my password or I'm
running as the root user already.
Similarly, if I go through and clear my screen,
if I go through and take a look at the permissions of my current terminal,
so ls ‑l,
and we can find out the terminal that I've connected to by going
through and running the tty command, the tty command will give me
the path through to the terminal,
and we can then go through and see that the tty group is listed
as the group owner with the write permissions.
Myself, as a Vagrant user, I've got read and write permissions.
If somebody wanted to message me, they would use the write command.
And if I go through and take a look at the /usr/bin,
and then the write program, we can see then that this is marked in yellow,
and we can see the S being set,
the group‑ID bit configured within the group permissions block.
So whenever anyone executes this, they're running with the permissions of the tty group.