chmod 1777 (rwxrwxrwt)
A directory everyone can write to, with one restriction: you can delete or rename only what is yours. It is the mode of /tmp, and the only sensible way to make a directory world-writable.
This tool runs in your browser. We never send what you type or paste to a server.
What chmod 1777 sets
| Who | Digit | Read | Write | Execute | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | yes | yes | yes | rwx |
| Group (g) | 7 | yes | yes | yes | rwx |
| Others (o) | 7 | yes | yes | yes | rwt |
The leading 1 sets the sticky bit, shown as t in place of an x.
chmod 1777 file # numeric
chmod a=rwxt file # the same, in symbolic form
ls -l shows this mode as -rwxrwxrwt on a file and drwxrwxrwt on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.
What the sticky bit changes
In a plain 777 directory, write permission lets anyone delete or rename anyone else's files. The sticky bit, which POSIX calls the restricted deletion flag, narrows that. An entry can be removed or renamed only by:
- the owner of the file,
- the owner of the directory, or
- root.
Creating files is unaffected: everyone still can. The contents of files are unaffected too, because those are governed by each file's own mode. A 666 file in /tmp can be overwritten by anyone, even though nobody but its owner can delete it.
Where it is used, and how to put it back
/tmp and /var/tmp are 1777 and owned by root. The same mode fits any drop directory that unrelated accounts must all be able to write to.
A /tmp that has lost the bit, typically after chmod 777 /tmp or a recursive chmod from /, lets every user remove or swap other users' temporary files. As root:
chmod 1777 /tmp
ls -ld /tmp # should show drwxrwxrwt
stat -c '%a %n' /tmp # GNU/Linux: 1777 /tmp
stat -f '%Mp%Lp %N' /tmp # macOS and BSD
The bit can also be set without stating the rest of the mode: chmod +t dir adds it and chmod -t dir removes it. A plain chmod 777 dir clears it.
A sticky directory is still shared ground
The bit stops deletion. It does not stop another user from getting to a file name first. A program that writes to a predictable path such as /tmp/myapp.log can find a file or a symbolic link already waiting there, planted by someone else, and end up writing where that person chose.
- Create temporary files with
mktemp, which picks an unpredictable name and creates the file for you alone;mktemp -ddoes the same for a directory. - Mind your umask. A file you create in
/tmpwith the default umask is 644: undeletable by others, but readable by all of them. - Check the kernel's extra protections on Linux. The sysctls below add rules for exactly this kind of directory. For instance, with
fs.protected_symlinksset to 1, a symbolic link in a world-writable sticky directory is followed only if it belongs to the process following it or to the owner of the directory.
sysctl fs.protected_symlinks fs.protected_hardlinks fs.protected_regular fs.protected_fifos
Variants: 1775, a capital T, and files
- 1775 (
rwxrwxr-t) is the group version: a team directory in which members cannot delete each other's files. - A capital
T, as indrwxrwxrwT(mode 1776), means the sticky bit is set but others have no execute permission, so they cannot use the directory in the first place. - On a regular file the bit has no function on Linux. On some older systems it asked the kernel to keep a program's image in swap, which is where the name "sticky" comes from.
1777 compared with its neighbours
Questions
What are the correct permissions for /tmp?
Mode 1777, owned by root, which ls -ld shows as drwxrwxrwt. If the t is missing, run chmod 1777 /tmp as root. Without the sticky bit any user can delete or replace other users' temporary files.
What does the t at the end of drwxrwxrwt mean?
It is the sticky bit, shown in place of the execute bit for others. In a directory it means a file can be deleted or renamed only by the file's owner, the directory's owner or root. A capital T means the sticky bit is set but others do not have execute permission.
Can other users read or change my files in /tmp?
The sticky bit only stops them deleting or renaming your files. Whether they can read or modify one depends on that file's own mode: with the usual umask it is 644, so they can read it but not write to it. Use mktemp, or set umask 077 first, for anything that should stay private.