Why does “chmod 1777” and “chmod 3777” both set the sticky bit

chmodpermissions

To set the sticky bit on a directory, why do the commands chmod 1777 and chmod 3777 both work?

Best Answer

Each number (also referred to as an octal because it is base8) in that grouping represents 3 bits. If you turn it into binary it makes it a lot easier.

1 = 0 0 1
3 = 0 1 1
5 = 1 0 1
7 = 1 1 1

So if you did 1777, 3777, 5777, or 7777 you would set the sticky bit because the third column would be a 1. However, with 3777, 5777, and 7777 you are additionally setting other bits (SUID for the first column, and SGID for the second column).

Conversely, any other number in that spot (up to the maximum of 7) would not set the sticky bit because the last column wouldn't be a 1 or "on."

2 = 0 1 0
4 = 1 0 0
6 = 1 1 0