Set User ID (SUID)
The Set User ID (SUID) bit enables an executable file to run with the privileges of its owner rather than those of the executing user. This feature is critical for commands likesu or passwd that require elevated privileges.
When the SUID bit is set on an executable without the owner’s execute permission, it is displayed as a capital
S. If the owner’s execute bit is also present, it appears as a lowercase s.Example: Setting SUID
-
Create a test file named
suidfileand view its default permissions: -
Set the SUID bit using the
chmodcommand with a four-digit octal number. For instance,4664sets the SUID bit along with standard permissions664: -
To include the owner’s execute permission (displayed as lowercase
s), usechmod 4764:
Set Group ID (SGID)
The Set Group ID (SGID) bit works similarly to SUID but affects the group ownership. When set, the file is executed with the group privileges that own the file instead of those of the executing user.Example: Setting SGID
-
Create a file named
sgidfileand inspect its default permissions: -
Set the SGID bit by using a leading digit of
2. For example, running:Notice the capitalSin the group’s execute position indicating that the SGID bit is set without execute permission. -
To enable execute permission as well, use
chmod 2674:
Finding Files with SUID and SGID
Locating files that have SUID or SGID bits set can be done with thefind command and the -perm option.
Examples:
-
Finding Files with SUID Set:
-
Finding Files with SGID Set:
chmod 6664 (where 4+2=6), you can search with /6000:
The Sticky Bit
The sticky bit is primarily used on directories shared by multiple users. It restricts file deletion or renaming so that only the file owner (and the root user) can perform these actions, regardless of the directory’s write permissions.Example: Setting the Sticky Bit on a Directory
-
Create a directory named
stickydirand check its permissions: -
Set the sticky bit using either symbolic mode (
+t) or octal notation. With1777, the sticky bit is set on a directory with777permissions: -
If the execute permission is removed (for example, with
chmod 1666), the sticky bit remains set but will display as uppercaseT:
This guide has provided detailed instructions on setting and verifying SUID, SGID, and Sticky Bit permissions in Linux systems. Mastery of these permission settings is crucial for secure system administration and file management. For further reading on managing file permissions and Linux security best practices, consider exploring additional Linux Documentation. Happy learning!