Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.

LPI Linux Essentials Exam 010-160 - Topic 5.4 - Special File Permissions

Set User ID (SUID)

File permissions in Linux are essential for maintaining security and managing user access to files and directories. Among these permissions, the Set User ID (SUID) plays a vital role in controlling executable files. SUID is a special kind of file permission given to a file. This permission allows users to run the file with the permission level of the file owner rather than the user who is running it. This feature can be incredibly beneficial for allowing controlled elevated access to users for specific tasks.

The SUID permission comes into play when a user executes a file. If the file has SUID permission, it doesn’t run with the privileges of the user who launched it but rather with the privileges of the file's owner. For example, if a file owned by the root user has SUID permission, and a regular user executes it, the file runs with root user privileges.

This is particularly useful for files that need to perform tasks that require higher privileges than what a normal user possesses. A common example is the /usr/bin/passwd file, which allows users to change their passwords. Changing passwords involves writing to system files that normal users don't have access to. With SUID permission, the passwd command runs with root privileges, enabling it to modify system files.

You can identify files with SUID permission through the file’s permission settings. When you list files in the detailed view using ls -l, files with SUID permission will have an s in the permission string. This s will be in the place of the owner’s execute permission bit. For instance:

  • A file with -rws------ permissions indicates that it has SUID permission.
  • The r means read, w means write, and s indicates execute with SUID.

To set SUID permission on a file, you use the chmod command with the +s attribute:

chmod u+s filename

To remove SUID permission, you replace + with -:

chmod u-s filename

It's important to note that only the root user or the owner of the file can set or remove the SUID permission.

While SUID is a powerful feature, it can also be a security risk. If a malicious user gains access to a file with SUID permission, they could potentially execute it with the privileges of the file owner, which might be the root. Therefore, it's vital to ensure that only trusted files have the SUID permission, and it should be used sparingly and under careful consideration.

When applying SUID permissions, it’s essential to monitor these files regularly and ensure they are up to date and secure. System administrators often audit SUID files as part of routine security practices to ensure that no vulnerabilities exist.

Set Group ID (SGID)

Similar to the Set User ID (SUID), the Set Group ID (SGID) is another crucial permission in Linux systems. It plays a significant role in managing file and directory permissions, particularly in collaborative environments. SGID can be assigned to both files and directories, and it controls how files are accessed and executed based on group permissions.

When SGID is applied to a directory, it ensures that files created within that directory inherit the group ownership of the directory, not the group of the user who created the file. This feature is particularly useful in shared directories, where it's important for files to maintain a common group ownership.

For executable files, when the SGID permission is set, the file executes with the privileges of the group that owns the file, instead of the group of the user executing the file. This is helpful in scenarios where users belonging to the same group require access to execute a file with group-level permissions.

SGID permission is indicated in the file or directory's permission settings. When you list files with ls -l, an SGID on a file is shown as an s in the group's execute permission spot. For example:

  • A file with permissions -rwxr-sr-x indicates that it has SGID permission.
  • A directory with permissions drwxr-s--- indicates that it has SGID permission.

To set SGID permission on a file or directory, the chmod command is used with the g+s option:

chmod g+s filename_or_directory

To remove SGID permission, the g+s is replaced with g-s:

chmod g-s filename_or_directory

Just like with SUID, careful consideration should be given to setting SGID permissions, especially on shared systems or directories.

One of the common uses of SGID is in shared project directories. By setting SGID on a directory, all new files created within it will inherit the directory's group ownership, ensuring that all team members have appropriate access to the files.

Another use of SGID is on shared executable files, where multiple users require the same level of group permissions to execute the file for collaborative tasks or operations.

It's important to handle SGID permissions with caution. Improper use of SGID can lead to security risks, such as unauthorized access to sensitive files or directories. Regular audits and careful management of SGID permissions are recommended to maintain a secure and efficient file permission system in Linux environments.

Sticky Bit

In Linux file systems, there's a special permission known as the Sticky Bit. This permission is unique and serves a specific purpose, particularly in shared and public directories. It's important to understand the Sticky Bit, how it works, and its role in file security and management.

The primary function of the Sticky Bit is to control the deletion of files in shared directories. When the Sticky Bit is set on a directory, it restricts file deletion in that directory. Only the file owner, the directory owner, or the root user can delete or rename files in the directory. This is especially useful in public directories like /tmp, where multiple users can create files but shouldn’t be allowed to delete or modify others' files.

You can recognize a directory with the Sticky Bit set by the t in the directory’s permission settings. When you use the ls -ld command to list directory permissions, a directory with the Sticky Bit will display permissions like drwxrwxrwt.

  • The t at the end of the permission string signifies the Sticky Bit.
  • If the Sticky Bit is set on a directory without execute permissions for others, you will see a T instead of a t.

To set the Sticky Bit on a directory, use the chmod command with the +t option:

chmod +t directory_name

Alternatively, you can use numeric mode. For example, chmod 1777 directory_name will set the Sticky Bit along with read, write, and execute permissions for everyone.

If you need to remove the Sticky Bit from a directory, simply use the chmod command with -t:

chmod -t directory_name

The Sticky Bit is commonly used on directories where files are temporarily stored, such as /tmp & /var/tmp. In such directories, it's important to prevent users from deleting or modifying other users' files, even if they have write permissions to the directory.

Another use case is in shared directories where multiple users work together. The Sticky Bit helps maintain order and prevents accidental or intentional deletion of files by users who don't own them.

While the Sticky Bit is a useful tool for managing shared directories, it’s important to use it appropriately. It doesn't restrict file creation within the directory; it only controls deletion. As such, directories with the Sticky Bit should still be monitored for unnecessary file accumulation or misuse. Regular cleanup and monitoring of such directories are recommended to ensure they are not misused or overloaded with unwanted files.


In summary, understanding and effectively managing file permissions in Linux is essential for maintaining system security and efficient operation. This guide covered three key permissions: Set User ID (SUID), Set Group ID (SGID), and the Sticky Bit. Each of these permissions serves a unique purpose:

  • SUID: Allows a user to execute a file with the permissions of the file's owner, often used for files that require elevated privileges for specific operations.
  • SGID: Similar to SUID but for group permissions. It ensures files within a directory inherit the directory's group ownership or allows files to be executed with the group's privileges.
  • Sticky Bit: Used primarily on shared directories to control file deletion, ensuring that only the file's owner, the directory's owner, or the root user can remove files.

Proper application and management of these permissions are vital for ensuring both the functionality and security of Linux systems. Careful consideration should be given when setting these permissions to avoid potential security risks. Regular audits and monitoring of these permissions can help in maintaining an optimal and secure environment.

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.