Linux Sticky Bit Explained — chmod 1777 and /tmp Security
Understand the sticky bit in Linux. How chmod 1777 protects /tmp by preventing users from deleting each other's files in world-writable directories.
Detailed Explanation
What Is the Sticky Bit?
The sticky bit is a special permission bit that restricts file deletion within a directory. When set on a directory, only the following users can rename or delete files within it:
- The file owner
- The directory owner
- The root user
This applies even if other users have write permission on the directory.
The /tmp Example
The most well-known use of the sticky bit is the /tmp directory:
$ ls -ld /tmp
drwxrwxrwt 15 root root 4096 Jan 01 00:00 /tmp
Notice the t at the end of the permissions. This is the sticky bit in action:
- Everyone can create files in /tmp (rwx for all)
- But users can only delete their own files
Without the sticky bit, any user could delete any other user's temporary files, which would break many programs.
Setting the Sticky Bit
# Using symbolic notation
chmod +t /shared/directory
chmod o+t /shared/directory
# Using octal notation (prefix with 1)
chmod 1777 /tmp
chmod 1775 /shared/directory
# Verify
ls -ld /shared/directory
# drwxrwxr-t ...
Sticky Bit Display
In ls -l output, the sticky bit appears in the others execute position:
- t (lowercase): Sticky bit + execute permission for others
- T (uppercase): Sticky bit WITHOUT execute permission for others
Practical Use Cases
# Shared upload directory
mkdir /var/uploads
chmod 1777 /var/uploads
# Shared project temp directory
mkdir /project/tmp
chmod 1770 /project/tmp # Only group members, with sticky bit
Sticky Bit on Files
On modern Linux, the sticky bit on regular files has no effect. It was historically used on older Unix systems to keep frequently used programs in swap space for faster loading.
Use Case
The sticky bit is essential for any shared directory where multiple users can write files but should not be able to delete each other's work. Beyond /tmp, it is useful for shared upload directories, collaborative workspaces, and any multi-user environment.
Try It — Linux Permission Reference
Related Topics
Linux SUID (Set User ID) Explained — chmod 4755 and Security
Special Permissions
Linux SGID (Set Group ID) Explained — Shared Directories with chmod 2775
Special Permissions
Why chmod 777 Is Dangerous — Security Risks Explained
Common Permissions
Linux Directory Permissions Explained — How rwx Differs for Directories
Directory & Web
chmod 755 Explained — Owner Full, Others Read+Execute
Common Permissions