What is the sticky bit and where is it used?

The sticky bit is set for the /Users/Shared folder by default. This makes this folder append only so that users can add to this folder but not remove from it.

The behavior of the folder is set by the sticky bit setting on the permissions of the folder, described below.

Files can be added but not removed by unprivileged users. Such a directory is termed a sticky directory. A sticky directory has the sticky bit set.

For example, the Shared directory is sticky.

% ls -al /Users
total 0
drwxrwxrwt 11 root wheel 330 Jul 7 19:36 Shared

Stickiness is indicated by a ‘t’ at the end of the permissions. ‘ls’ replaces ‘x’ in the others permissions triplet with ‘t’.

How is the Sticky Bit Set?

As with all other permissions, ‘chmod’ is used to set and clear the sticky bit.

% mkdir test
% ls -ald test
drwxr-xr-x 2 melkor staff 24 Jul 12 16:08 test
% chmod u+t test
% ls -ald test
drwxr-xr-t 2 melkor staff 24 Jul 12 16:08 test
The sticky bit is set.

% chmod u-t test
% ls -ald test
drwxr-xr-x 2 melkor staff 24 Jul 12 16:08 test
The sticky bit is cleared.

You may also use ‘g+t’ which has exactly the same effect; ‘o+t’ has no effect.