What chmod 1777 means
| Who | Digit | Letters | On a file | On a directory |
|---|---|---|---|---|
| owner | 7 |
rwx |
Can read, modify and run | Can list files, create, delete and rename files and enter it and open files |
| group | 7 |
rwx |
Can read, modify and run | Can list files, create, delete and rename files and enter it and open files |
| others | 7 |
rwx |
Can read, modify and run | Can list files, create, delete and rename files and enter it and open files |
Each digit is the sum of read (4), write (2) and execute (1), and the leading digit sets the special bits: setuid (4), setgid (2) and sticky (1). In
ls -l output it looks like this:
$ ls -l
drwxrwxrwt 2 alice staff 4096 Oct 21 10:30 example-dir
- The owner can read, write and execute.
- The group can read, write and execute.
- Everyone else can read, write and execute.
- Sticky bit: in a directory, only a file’s owner can delete or rename it.
When to use 1777
- /tmp and /var/tmp
- Shared upload or drop directories
The sticky bit (the leading 1) means that in a world-writable directory, users can only delete or rename their own files. This is exactly how /tmp works, and ls -ld /tmp shows drwxrwxrwt. Without the sticky bit, any user could delete anyone else’s temporary files.
Is chmod 1777 safe?
Yes, for shared directories. The sticky bit stops users from deleting each other’s files.
Commands
# One file or directory
chmod 1777 path
# Same thing in symbolic form
chmod u=rwx,g=rwx,o=rwxt path
# Every directory under a tree (leaves files alone)
find /path/to/dir -type d -exec chmod 1777 {} +
# Check the result
stat -c '%a %A %n' path # Linux
stat -f '%Lp %Sp %N' path # macOS
Avoid chmod -R 1777 on a whole tree: it gives files and directories the same mode. The
find form above changes only directories.
Other chmod values
777 · 775 · 770 · 755 · 751 · 750 · 744 · 711 · 700 · 666 · 664 · 660 · 644 · 640 · 600 · 555 · 500 · 444 · 400 · 000 · 2775 · 4755
Need a different combination? Use the Chmod Calculator.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What does chmod 1777 mean?
chmod 1777 sets the permissions to rwxrwxrwt. The owner can read, write and execute. The group can read, write and execute. Everyone else can read, write and execute. Sticky bit: in a directory, only a file’s owner can delete or rename it.
Is chmod 1777 safe?
Yes, for shared directories. The sticky bit stops users from deleting each other’s files.