Skip to main content
Welcome to this comprehensive guide on SUID, SGID, and Sticky Bit permissions. In this article, we explain each special permission, demonstrate how to set them, and show how to verify their status using practical examples. These advanced permission settings are essential for managing command privileges and shared directory access in Linux systems.

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 like su 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

  1. Create a test file named suidfile and view its default permissions:
  2. Set the SUID bit using the chmod command with a four-digit octal number. For instance, 4664 sets the SUID bit along with standard permissions 664:
  3. To include the owner’s execute permission (displayed as lowercase s), use chmod 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

  1. Create a file named sgidfile and inspect its default permissions:
  2. Set the SGID bit by using a leading digit of 2. For example, running:
    Notice the capital S in the group’s execute position indicating that the SGID bit is set without execute permission.
  3. 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 the find command and the -perm option.

Examples:

  • Finding Files with SUID Set:
  • Finding Files with SGID Set:
Additionally, to find files that have either or both of these permissions, combine their values. For example, if a file is set with both SUID and SGID using 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

  1. Create a directory named stickydir and check its permissions:
  2. Set the sticky bit using either symbolic mode (+t) or octal notation. With 1777, the sticky bit is set on a directory with 777 permissions:
  3. If the execute permission is removed (for example, with chmod 1666), the sticky bit remains set but will display as uppercase T:

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!

Watch Video