Now let's take a look at S UI DS G ID and the sticky bit.
An S UI D is a special permission that allows users
to run an executable with the permissions of the executable's owner.
Now,
Emily has built an application that reads
reports from a folder containing reports.
She can access file reports and the files located in user local reports.
Now, she would like John's help with filing reports,
but she doesn't want to give John full access
to the folder that our application is reading.
However, with an S UI D bit set, John can run the file reports application
and it will assume Emily's permissions and read the files in the folder.
So he's able to run an executable
using Emily's permissions without having Emily's permissions in that folder.
Now, this is just a simple example,
but this is useful when you need to allow
users to perform specific actions that require elevated privileges,
but you don't want to grant them full access to the owner's account
SG ID is a similar permission,
but it applies to both executables and directories.
So in our case, our file reports application is a member of the reports group.
So John and Emily can run the application
and that application has permissions of the reports group.
Now, if they create new files in this directory,
those files will also be a part of the reports group.
This is useful when you have folks collaborating on files
and you want to maintain group ownership of those files.
Now, the sticky bit is a special permission that can be set on directories
and it restricts file deletion in that directory.
So if Emily creates a file in user, local reports
and that reports has a sticky bit set,
John can't come in and delete the file.
Only the file owner,
directory owner or super user root can delete the files.
This is useful for things in shared
directories where multiple users can create files
but should not be able to delete or modify files created by other people.
Let's move to a small demo to show these in action.
So these are gonna be relatively straightforward.
We're just going to show you what the permissions look like.
We'll start with the S UI D bit, which is the set user identification bit.
And as we said, when this is set on a file, it means that whenever the file is executed,
it's going to be executed as the user id of the owner of
the file instead of the user id of the person running the file.
So that's useful for things like when you use the su command to switch users
or say the password command when you go to change your
password as a regular user and it runs as you,
let's create a test file.
We're gonna call it S UI D file. Let's take a look at its default permissions.
Now,
we can see that it has some read and write permissions for
user and group and read only for the all others group.
So let's take a look at how we can set and recognize the UI D permissions.
We're going to do that with our
CH mod command.
And before we use three digit permissions in octal format,
so we're going to add 1/4 digit here
and the first digit is going to be our suid
digit,
which is four.
So to set that you need a four in that place and then
you can specify any of your other permissions you would like to set.
So let's say 664.
And remember you can type the first few letters of
the file name and press tab to autocomplete it.
So let's take a look at the permissions on that file
notice in the place of the execute bit for the user, we have a capital S.
So this lets us know that the S UI D bit is enabled for this file.
So if anybody else were to execute the file,
it would be executed as the user Jeremy instead of the user who executed it.
Also, if you do a chmod 4764.
With this permission setting, our user owner has execute permissions
and it's gonna look a little bit different.
So instead of that capital S, you're gonna have a lowercase S.
So when you see a capital S, that means S UI D is enabled,
but there's no execute permission.
When you see a lowercase X in this position,
that's gonna mean the execute bit and the S UI D bit are both set.
Now, let's take a look at group ID.
So set group id is pretty much the same as set user id only.
It's going to apply for the group on a file.
So we're gonna make a file
and we're gonna say this is a SG ID file
and we look at the permissions that looks pretty normal.
So we're gonna set it similarly,
but it takes a two instead of a four as the leading digit.
So we could say that this is a 664.
Now when we look at its permissions, we have a capital S in the execute place
of the group for its permissions.
So similarly with S UI D, there's no execute bit set here.
So it's going to be a capital S
if we wanna set the group and execute bit, also,
we'll change this third digit to a seven
and we take a look at it and that becomes a lowercase S
so you can recognize the set group id.
So sometimes you might be asked to find files that have
the S UI D bit or the SG ID bit set.
Now,
let's do a find here with the permission flag and we'll set a four for the first digit
and we don't care about the remaining permissions.
So we can just put four and all zeros
and we run it and there's our S UI D file.
Now, if you want to find SG ID files,
you could use a two.
And similarly, we can set them both on a file. So let's create a file named both.
And we're going to see H mod
and four plus two is six, right?
So for both of them, the leading digit is six.
So add six is our first digit, then 664, for example,
and we can see that both S UI D and SG ID are set.
And if we do a fine
dot dash perm slash 6000,
we'll find all the files that have either the S UI D set,
SG ID set or both.
And lastly, we're going to look at the sticky bit.
So as we covered,
the sticky bit is usually set on directories that are shared between people.
And it's going to allow the user that owns the file inside of that directory.
And the root user will be the only people that can remove that file from the directory
no matter what the permissions on the directory are
only the user owner and root can remove them.
So let's make a directory and we're gonna call it sticky.
Ok. We'll take a look at that permissions
and those are the directory permissions that we'd expect.
So we can do a chmod plus T
and this is a shorthand way to do it.
Now, if you want to get more fine grained with permissions,
you can put a one in the leading position
and then 777, for example.
All right.
And you can see what it looks like when the sticky bit is set on our directory.
Notice this T at the end a lowercase T is there because the sticky bit is set
and the execute bit is set.
If we were to take the execute bit off,
like we do 1666,
then look at those permissions and you see a capital T here.
So it's very similar to the bits that we saw before.
So that does it for our brief introduction to the set user ID, set group,
id and sticky bit permissions.
I hope this makes sense.
And I'll see you in the next video.