chmod 1777: sticky bit (rwxrwxrwt)
chmod 1777 is 777 plus the sticky bit (the leading 1). Everyone can create files in the directory, but a file can only be deleted or renamed by its owner, the directory's owner, or root. ls -l shows it as a t at the end: rwxrwxrwt. This is the mode of /tmp.
chmod 1777 = rwxrwxrwt: everyone full access, plus sticky.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner (user) | 7 | |||
| Group | 7 | |||
| Others | 7 | |||
| Special | 1 |
7Owner (user): 7 = 4 read + 2 write + 1 execute7Group: 7 = 4 read + 2 write + 1 execute7Others: 7 = 4 read + 2 write + 1 execute1Special bits: 1 sticky: in a shared directory, only a file's owner (or root) can delete or rename it
World-writable with the sticky bit: the standard mode for shared directories such as /tmp. Anyone can create files, but only a file's owner can delete or rename it. On a regular file it is still a hole.
On a file
- Owner (user) read it, change it and run it as a program
- Group read it, change it and run it as a program
- Others read it, change it and run it as a program
On a directory
- Owner (user) list the names inside, enter it and open files by name, create and rename and delete entries
- Group list the names inside, enter it and open files by name, create and rename and delete entries
- Others list the names inside, enter it and open files by name, create and rename and delete entries
chmod 1777 filechmod u=rwx,g=rwx,o=rwxt filels -l → -rwxrwxrwt
What to know
Without the sticky bit, write permission on a directory lets a user remove or rename any entry in it, whoever owns the file. On a shared directory like /tmp, that would let any user delete or swap out another user's temporary files. The sticky bit removes that ability.
On Linux, /tmp, /var/tmp and /dev/shm are normally 1777. The bit only matters on directories; Linux ignores it on regular files.
Where it fits
- /tmp, /var/tmp and other world-writable scratch directories
- Shared drop or upload directories where users must not delete each other's files (often as 1770 or 3775 instead of 1777)
Gotchas
- It does not protect file contents: a world-writable file inside /tmp can still be edited by anyone. Programs should create temp files with
mktemp, which uses mode 600. - A capital
T(for example 1776) means sticky is set but others lack execute, so they cannot use the directory anyway. - Because 1777 contains world write, tools that flag world-writable paths will list it. On a /tmp-style directory with the sticky bit, that is expected.
- If /tmp loses its sticky bit (for example after restoring it from a backup without modes, or a mistaken
chmod 777 /tmp), restore it withchmod 1777 /tmp.
Related explainers
- chmod 777 (rwxrwxrwx)chmod 777 lets every user on the system read, change and run a file. Why it is almost always the wrong fix...
- chmod 2775: setgid directory (rwxrwsr-x)chmod 2775 makes a directory shared: files created in it inherit its group. How to set up a team directory...
- chmod 4755: setuid (rwsr-xr-x)chmod 4755 sets the setuid bit: the program runs with its owner's privileges. How /usr/bin/passwd uses it,...