What Is SUID GUID and Sticky Bit
What Is SUID GUID and Sticky Bit
There are 3 special permissions that are available for executable files and directories. These are:
1. SUID permission
2. SGID permission
3. Sticky bit
Set-user Identification (SUID)
Have you ever thought, how a non-root user can change his own password when he does not have
write permission to the /etc/shadow file. hmmm interesting isnt it? Well to understand the trick
check for the permission of /usr/bin/passwd command :
# ls -lrt /usr/bin/passwd
-r-sr-sr-x 1 root
sys
If you check carefully, you would find the 2 Ss in the permission field. The first s stands for
the SUID and the second one stands for SGID.
When a command or script with SUID bit set is run, its effective UID becomes that of the
owner of the file, rather than of the user who is running it.
Another good example of SUID is the su command :
# ls -l /bin/su
-rwsr-xr-x-x 1 root user 16384 Jan 12 2014 /bin/su
SGID permission is similar to the SUID permission, only difference is when the script or
command with SGID on is run, it runs as if it were a member of the same group in which the
file is a member.
# ls -l /usr/bin/write
-r-xr-sr-x 1 root tty 11484 Jan 15 17:55 /usr/bin/write
Note :
If a lowercase letter l appears in the groups execute field, it indicates that the setgid bit is
on, and the execute bit for the group is off or denied.
When SGID permission is set on a directory, files created in the directory belong to the group
of which the directory is a member.
For example if a user having write permission in the directory creates a file there, that file is
a member of the same group as the directory and not the users group.
This is very useful in creating shared directories.