In the Linux ecosystem, file and directory permissions are foundational to security and access control. While most users are familiar with the basic read (r), write (w), and execute (x) permissions, there exist "special permissions" that add nuance to how files and directories behave. One such special permission is the Sticky Bit—a powerful tool designed to protect files in shared directories from accidental or malicious deletion.
Whether you’re a system administrator managing multi-user servers, a developer collaborating on shared projects, or a curious user exploring Linux internals, understanding the Sticky Bit is critical for maintaining secure and functional shared environments. In this blog, we’ll demystify the Sticky Bit: its purpose, how it works, syntax, practical examples, and best practices.
Before diving into the Sticky Bit, let’s recap Linux file permissions. Every file and directory in Linux has a set of permissions governing access for three user categories:
User (u): The owner of the file/directory.
Group (g): Users belonging to the file’s group.
Others (o): All other users on the system.
Permissions are represented by three sets of characters (e.g., rwxr-xr--), where:
r (read): Allows viewing content.
w (write): Allows modifying or deleting the file/directory.
x (execute): Allows running a file or accessing a directory.
These permissions can be viewed with ls -l and modified with chmod. Beyond the basic rwx permissions, Linux supports special permissions—including the Sticky Bit, SetUID, and SetGID—which add advanced access controls.
The Sticky Bit (t) is a special permission designed for directories. Its primary purpose is to prevent users from deleting or renaming files owned by other users in shared directories.
Originally, the Sticky Bit was used on executable files to "stick" them in memory (reducing load times) on older Unix systems. This functionality is obsolete in modern Linux, where the Sticky Bit has no effect on regular files. Today, it is exclusively used for directories.
Users with write access to the directory can still create files and subdirectories.
However, a user can only delete or rename files they own (or files owned by the directory’s owner/root).
This ensures that even in a directory with open write permissions (e.g., rwxrwxrwx for "others"), users cannot accidentally or maliciously delete each other’s files.
Key Note: The Sticky Bit has no effect on regular files in modern Linux. It only modifies the behavior of directories.
In ls -l output, the Sticky Bit appears as a t (lowercase) or T (uppercase) in the "others" execute position (the 10th character of the permission string).
Lowercase t: The Sticky Bit is set, and the "others" category has execute (x) permission.
Example: drwxrwxrwt (common for /tmp).
Uppercase T: The Sticky Bit is set, but the "others" category lacks execute (x) permission.
Example: drwxrwxrwT (rare, but possible if x is not granted to others).
The /tmp directory is a classic example of a shared directory with the Sticky Bit enabled. It is world-writable (anyone can create files), but the Sticky Bit prevents users from deleting others’ files.
Check /tmp permissions:
ls -ld /tmp
Output:
drwxrwxrwt 10 root root 4096 Oct 1 12:00 /tmp
Here, drwxrwxrwt indicates:
d: Directory.
rwxrwxrwx: Read/write/execute for user, group, and others.
t: Sticky Bit set (lowercase, since "others" have x).
The Sticky Bit is essential for shared directories where multiple users need write access but should not interfere with each other’s files. Common use cases include:
/tmp and /var/tmp: System-wide temporary directories.
Team Project Directories: Shared workspaces for developers (e.g., /opt/team-shared).
Public Upload Directories: Web servers (e.g., ftp/uploads or nginx/www/uploads), where users upload files but shouldn’t delete others’ uploads.
Multi-User Environments: Shared folders in universities, labs, or enterprise systems.
Use Sparingly: Only set the Sticky Bit on directories explicitly intended for shared write access (e.g., avoid overusing it on personal directories).
Combine with Least Privilege: Pair the Sticky Bit with restrictive group/user permissions (e.g., 1770 instead of 1777) to limit access to trusted users.
Audit Regularly: Use find / -perm -1000 -type d 2>/dev/null to list all sticky directories and verify they’re still needed.
Avoid 1777 Unless Necessary:rwxrwxrwt (1777) allows world-write access. Prefer 1770 (group-only write) or 1755 (user-write only) when possible.
The Sticky Bit is a critical tool for securing shared directories in Linux. By preventing accidental or malicious deletion of others’ files, it enables safe collaboration in multi-user environments. Whether you’re managing /tmp, a team project folder, or a public upload directory, understanding and using the Sticky Bit ensures data integrity and security.
Remember: The Sticky Bit is for directories, uses t/T in permissions, and is set with chmod +t or numeric 1. Use it wisely, and always pair it with least-privilege access controls!