chmod 1777: The Sticky Bit and Why /tmp Needs It
1777 is rwxrwxrwt: a world writable directory with the sticky bit set. The sticky bit restricts deletion, so only a file's owner, the directory's owner or root may remove or rename an entry, which is what makes a shared directory usable.
At a glance
- Octal
- 1777. The leading 1 is the sticky bit
- Symbolic
- u=rwx,g=rwx,o=rwxt
- On a directory
- drwxrwxrwt
- Effect
- Restricted deletion. Only the entry's owner, the directory's owner or root may remove or rename it
- Effect on a file
- None on Linux. The historical meaning of keeping a program in swap is long gone
- Lowercase t or capital T
- t means sticky with the others execute bit set. T means sticky without it
- In the calculator
- Available as the 1777 preset and as a sticky bit checkbox
In detail
Write permission on a directory normally lets you delete anything in it, regardless of who owns the file. On a shared directory that is intolerable: any user could remove another user's temporary files. The sticky bit changes the rule so that removal and renaming require you to own the entry, own the directory, or be root.
This is why /tmp is 1777 and not 777. Every account needs to create temporary files there, and no account should be able to delete anyone else's. The same mode appears on /var/tmp and on /dev/shm for the same reason, and it is the single correct answer whenever someone reaches for 777 on a directory that several users share.
The trailing t in a listing is where the sticky bit shows up, in the position that would otherwise hold the others execute bit. Lowercase t means sticky and execute are both set, which is the working combination. Capital T means the sticky bit is set while others cannot traverse the directory at all, which is usually a mistake.
It restricts deletion, not writing. A file inside a sticky directory whose own mode is world writable can still have its contents replaced by anyone, because that permission comes from the file, not from the directory. The sticky bit stops the file being unlinked and replaced, not overwritten in place.
For a directory that does not need to be world writable, the better answer is usually a shared group with 2775 rather than 1777. Reach for the sticky bit when the set of users genuinely cannot be enumerated in a group, which in practice means system wide temporary space and little else.
Examples
chmod 1777 /srv/shared-tmp
chmod u=rwx,g=rwx,o=rwxt /srv/shared-tmp$ ls -ld /tmp
drwxrwxrwt 10 root root 4096 /tmp
$ whoami
bob
$ rm /tmp/alice-session.sock
rm: cannot remove '/tmp/alice-session.sock': Operation not permitted
Without the sticky bit that removal would succeed.chmod +t /srv/dropbox
# or, setting the whole mode at once
chmod 1733 /srv/dropbox -> drwx-wx-wtThings that catch people out
- The sticky bit stops deletion, not modification. A world writable file in a sticky directory can still be rewritten in place by anyone.
- It has no effect on regular files on Linux. Setting it on a file is harmless and pointless, and shows up as T because files rarely have the others execute bit.
- 1777 is still world writable, so hardening scans flag the directory. That is expected for /tmp and needs justifying anywhere else.
- Capital T in a listing means the sticky bit is set on a directory that others cannot traverse, so nobody outside the owner and group can use it in the first place.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 777: Everyone Gets Everything
777 gives read, write and execute to the owner, the group and everyone else. What it actually allows, why it is never the real fix, and what to use instead.
chmod 733: Blind Drop Directories and What They Miss
733 lets others write and traverse a directory without listing it. The upload drop box pattern, and why it needs the sticky bit to be safe.
chmod 2775: The setgid Bit on Directories and on Files
2775 adds the setgid bit to 775 so new files inherit the directory's group. The fix for shared directories where the team cannot edit each other's files.
How to Read an ls -l Permission String Such as rwxr-xr-x
The ten characters at the start of an ls -l line decode to a file type and three permission classes. What s, S, t, T and a trailing plus mean.
The Execute Bit on a Directory Means Traverse, Not Run
On a directory, execute grants the right to resolve names through it and read grants the right to list them. Why a directory at 644 cannot be entered.
umask: How the Default Mode of a New File Is Decided
umask removes permission bits from newly created files and directories. Why 022 gives 644 and 755, and why a new file is never executable.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder