setuid, setgid and sticky bit
In this section, we will show you everything you need to know about the special file permission flags, setid
, setgid
, and the sticky bit
.
setuid
Now let's talk about setuid
, setgid
, and the sticky bit
. As we work with users, groups, and file permissions, let's first log in as root.
First, let's create a new user, group, and the copy of the whoami
command locally to see what's going on with the setuid
flag:

Next, let's change the file owner and group owner of this command to awesome_user
and awesome_group
:

Setting the setuid
, setgid
, and the sticky bit
can also be done using octal notations. You already know about them from the file permissions chapter. These special permissions can be represented by one single additional bit in the file permission string, using the following code:

The setuid
has the number 4
, the setgid
the number 2
, and the sticky bit
the number 1
. Similar to the files' simple read
, write
, and execute
permissions, here you can also add combinations...