The sticky bit, when set on a directory, restricts file deletion: a user may delete or rename a file in the directory only if they own the file, regardless of write permission on the directory itself. This is exactly what you want for /tmp: everyone can write their own files, but no one can delete anyone else's.
ls -ld /tmp
drwxrwxrwt 10 root root ... /tmp # 't' at the end
chmod +t mydir # set the sticky bit
chmod 1777 mydir # octal (1 = sticky)
Historically, the sticky bit on executable files had a different meaning on Unix: it hinted that the executable should be kept in swap rather than discarded after use, to speed up repeated launches. Modern Linux ignores the bit on files; only its directory meaning remains relevant.
/tmp, /var/tmp, and /dev/shm all have the sticky bit set by default. Without it, a malicious user could delete another user's files from /tmp at will, which would wreak havoc on shared systems.
Discussed in:
- Chapter 9: Users, Groups, and Permissions — Special Bits: setuid, setgid, and sticky
Also defined in: Textbook of Linux