Skip to content

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

Which permission bits each class has
WhoRead (4)Write (2)Execute (1)Digit
Owner (u)YesYesYes7
Group (g)YesYesYes7
Others (o)YesYesYes7

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.

What each class can do with a file and with a directory
WhoOn a fileOn a directory
Owner (u)Read, modify and runList, enter, create, delete and rename entries
Group (g)Read, modify and runList, enter and create entries; delete or rename only their own
Others (o)Read, modify and runList, 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

Representations of this mode
Octal1777
Symbolicrwxrwxrwt
ls -l, file-rwxrwxrwt
ls -l, directorydrwxrwxrwt
Equivalent symbolic commandchmod a=rwx,+t
Default umask that creates itNone of the common umasks; set it explicitly with chmod
How Git records a file with it100755 (executable)
Special bitssticky

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

Set it on one file or directory
sudo chmod 1777 /srv/scratch
sudo chmod a=rwx,+t /srv/scratch   # same result
Check the result
stat -c '%a %A %n' /srv/scratch     # Linux (GNU stat): 1777 drwxrwxrwt
stat -f '%Mp%Lp %Sp %N' /srv/scratch   # macOS and BSD

Applying 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.