breakitdown

chmod 1777: sticky bit (rwxrwxrwt)

Answer

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.

Try

chmod 1777 = rwxrwxrwt: everyone full access, plus sticky.

Read 4Write 2Execute 1Digit
Owner (user)7
Group7
Others7
Special1
  1. 7
    Owner (user): 7 = 4 read + 2 write + 1 execute
  2. 7
    Group: 7 = 4 read + 2 write + 1 execute
  3. 7
    Others: 7 = 4 read + 2 write + 1 execute
  4. 1
    Special 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

Gotchas

Related explainers

← chmod calculator