chmod 1777
chmod 1777 sets rwxrwxrwt: everyone can list, enter and create files in the directory, and the sticky bit (the t) means a file can only be deleted or renamed by its owner, the directory owner or root.
Permission matrix
| Who | Read (4) | Write (2) | Execute (1) | Digit |
|---|---|---|---|---|
| Owner (u) | Yes | Yes | Yes | 7 |
| Group (g) | Yes | Yes | Yes | 7 |
| Others (o) | Yes | Yes | Yes | 7 |
Execute means different things by type. On a file it lets the kernel run it as a program. On a directory it is search permission: entering it (cd) and reaching the files inside by name. Read on a directory only lists names.
| Who | On a file | On a directory |
|---|---|---|
| Owner (u) | Read, modify and run | List, enter, create, delete and rename entries |
| Group (g) | Read, modify and run | List, enter and create entries; delete or rename only their own |
| Others (o) | Read, modify and run | List, enter and create entries; delete or rename only their own |
Special bits in this mode
- sticky (1000): in a directory, only a file's owner, the directory's owner or root can delete or rename that file. Linux ignores it on regular files.
Facts
| Octal | 1777 |
|---|---|
| Symbolic | rwxrwxrwt |
| ls -l, file | -rwxrwxrwt |
| ls -l, directory | drwxrwxrwt |
| Equivalent symbolic command | chmod a=rwx,+t |
| Default umask that creates it | None of the common umasks; set it explicitly with chmod |
| How Git records a file with it | 100755 (executable) |
| Special bits | sticky |
When to use it
- World-writable scratch directories: /tmp, /var/tmp and /dev/shm are drwxrwxrwt on Linux. Without the t, any user could delete another user's temporary files or swap them for their own.
- Drop directories on multi-user machines where people leave files for each other but must not remove each other's.
When not to use it
- On regular files: Linux ignores the sticky bit on files. It only means something on directories.
- As a substitute for access control: everyone can still read every file whose own mode allows it. Programs writing to shared temp space should create files with mktemp (mode 600).
- For team folders where people must edit each other's files: use a group and 2775 instead.
Commands
sudo chmod 1777 /srv/scratch
sudo chmod a=rwx,+t /srv/scratch # same resultstat -c '%a %A %n' /srv/scratch # Linux (GNU stat): 1777 drwxrwxrwt
stat -f '%Mp%Lp %Sp %N' /srv/scratch # macOS and BSDApplying it to a whole tree
Set 1777 on the shared directory itself, not recursively. The files inside keep the modes their creators gave them; applying 1777 to them would make each one world-writable and executable.
Frequently asked questions
- What does the t in rwxrwxrwt mean?
- The sticky bit (octal 1000), shown in the others execute slot. Lowercase t means execute is also set; uppercase T means the sticky bit is set without execute for others.
- What permissions should /tmp have?
- 1777, owner root. If /tmp was accidentally changed, restore it with sudo chmod 1777 /tmp.
- How do I set just the sticky bit?
- chmod +t dir adds it without touching the other bits; chmod -t dir removes it. With numbers, the leading 1 in 1777 is the sticky bit.
Last reviewed by Arielton Oberek.