4

I know rwx = 7 in absolute permissions or numerical/octal representation of the permissions.

But what number is used to represent permission rws? (where the s is the set-uid bit that tells execution to happen with the privileges of the file owner).

For example: rwxrwsr--

I have never heard of anything higher that 777 so perhaps is there not a numerical representation for this?

Additionally, is it possible to have the set-uid bit in both user and group (ex. rwsrwsr--)? And if so what would be the numerical representation for this?

JFreeman
  • 143

2 Answers2

5

Octal permissions actually have 4 digits.

777 is just a short version for 0777, where the first digit is for setuid (4) and setgid (2).

chmod 6777

will set setgid + setuid (4+2=6)

See also:

pLumo
  • 26,947
  • Thank you! Super helpful. I hadn't realized the first octal bit was used in this way. So to confirm rwxrwsr-t would then have a 5 in the first digit as setuid and sticky bit? – JFreeman Mar 15 '22 at 10:17
  • @JFreeman It would be 3775 since the s comes at group's place (=2). – iBug Mar 16 '22 at 06:55
3

The special modes can be set numerically (octal) with a prefix like this:

The setuid bit is set with 4000 e.g: "chmod 4755 file".

The setgid bit is set with 2000 e.g: "chmod 2755 file".

The sticky bit is set with 1000 e.g: "chmod 1755 file".

So setting a setuid bit only on a file with "777" permissions is done like this:

chmod 4777 file

Reference: Permissions Calculator.

Artur Meinild
  • 26,018