HOWTO · Linux
The Purpose of Sticky Bit in Linux
This tutorial demonstrates the purpose of the sticky bit in Linux, explaining its importance in file management and security in shared environments. Learn how to set and remove the sticky bit using simple commands to enhance your Linux experience.
On this page
On Linux, the sticky bit on a shared writable directory restricts who can remove or rename entries. Set it with chmod +t, check it in the directory permissions with ls -ld, and remove it with chmod -t.
What the Sticky Bit Does
On Linux, the sticky bit is mainly useful on a directory that many users can write to, such as /tmp. It limits who may remove or rename entries in that directory: the entry’s owner, the directory’s owner, or a privileged process can do so. It does not prevent other users from reading or otherwise accessing files when the directory and file permissions allow it.
The sticky bit works alongside the directory’s ordinary permissions. For example, a shared directory can allow users to create entries while stopping one user from removing another user’s entry. A sticky bit on an ordinary file is not the modern Linux behavior covered here; this guide focuses on directories.
Set the Sticky Bit on a Directory
Use chmod +t on the directory whose permissions you intend to change. Replace /shared with the exact directory path you manage. The command changes that directory’s mode, so check the path and your authority to change it first.
Run this example:
directory=$(mktemp -d)
trap 'rmdir "$directory"' EXIT
chmod +t "$directory"
chmod a+rwx "$directory"
stat -c '%A' "$directory"
drwxrwxrwt
The permission string ends in t when the sticky bit and the relevant execute permission are set. This single-user example shows the permission marker only; it does not demonstrate deletion behavior between multiple users. The sticky bit is set before chmod a+rwx makes the temporary directory writable by everyone, so it is never world-writable without the sticky restriction. For an existing shared directory, the direct command is chmod +t /shared; it preserves the other permission bits. The example creates a temporary directory so it can demonstrate the change without altering a system or shared directory.
Verify the Sticky Bit
Inspect the directory itself with ls -ld /shared (use the path you changed). The final character in the permission string is t when the sticky bit is set and the directory’s other-execute bit is on, as in drwxrwxrwt. If the sticky bit is set but that execute bit is off, the final character is uppercase T. This marker reports the mode; it does not demonstrate how different users will be able to access the directory or its entries.
Remove the Sticky Bit
To remove the setting, run chmod -t /shared, replacing the example path with the intended directory. Then run ls -ld /shared again. A lowercase t or uppercase T at the end should no longer appear. The directory’s other permission bits remain as they were, so removing the sticky bit does not automatically make the directory writable or change who can access its files.
Common Questions
How can I check whether it is set? Use ls -ld with the directory path and inspect the final permission character. A t or T indicates the sticky bit; the case reflects the other-execute bit.
Why use it in a shared writable directory? It prevents ordinary users from removing or renaming entries owned by other people, while allowing the directory owner and privileged processes to manage entries. This is why shared directories such as /tmp commonly use it.
Does it stop other access to a file? No. The sticky bit limits removal and renaming within that directory. Read, write, and traversal access still depend on the relevant directory and file permissions.
Can I set it on a regular file, and how do I undo it? This tutorial covers its useful modern Linux directory behavior; setting the bit on an ordinary file is not the behavior demonstrated here. Remove it from a directory with chmod -t /path/to/directory, then inspect the mode with ls -ld.