Frequently Asked Question

Why does /tmp have a sticky bit, and what does it do?

/tmp has to be world-writable so that any program can drop scratch files there, but world-writable without protection would let one user rm another user's open files, a denial-of-service waiting to happen. The sticky bit (octal 1000, shown as t in the others' execute position, hence drwxrwxrwt on ls -ld /tmp) solves that. On a directory it tells the kernel: only the owner of a file (or root) may delete or rename it, regardless of whether other users have write permission on the containing directory.

So in /tmp, every user can create files, every user can list the directory, every user can read or write their own files, but no one can rip files out from under anyone else. The same trick is used for /var/tmp and /dev/shm. To set the bit explicitly, chmod 1777 /some/shared/dir or chmod +t /some/shared/dir. Historically the bit had a different meaning on files (keep the program's text segment in swap), but that usage is long-dead and the bit is ignored on regular files in Linux today.

Further reading and video