ACs
ACs

Reputation: 1445

What are 4th and 5th digits in linux permission?

I'm trying to understand the permission system of Linux. I understand the groups:

(I've read something about setuid/setgid and sticky bit and I don't really understand what they are good for.)

The other thing I don't understand for example in PHP the 5 digits of permission instead of 3: So what does this do?

mkdir($directory, 02770);

277 Should mean write perm for the owner, and everything for the group and other users, but what does the first and last digit mean?

Upvotes: 2

Views: 2045

Answers (2)

Basche-Ralf
Basche-Ralf

Reputation: 19

late but here is the answer to your last question: Bits 11...9 stand for SUID, SGID, Sticky, this info can be easily found. But there are altogether 16 permission bits. Bits 15...12 code the type of "file": 0001=p=fifo (pipe), 0010=c=character device, 0100=d=directory, 0110=b=block device, 1000="normal" file, 1010=l=link (soft link file), 1100=s=socket According to this, the "4" simply says "directory".

Upvotes: 1

9000
9000

Reputation: 40894

More about setuid, setgid, and sticky bit in Wikipedia.

  • setuid: the executable file is started with the privileges of the file owner (not the user starting the process).
  • setgid: the executable file is started as if the user belonged to the group to which the file belongs.
  • sticky: does not allow to delete or rename files in a directory where the user has the write permission, unless the files also belong to the user.

The constant is shown as 5-digit but the first digit is always 0; it is a convention for octal literals (that is, 010 is 8, not 10). This makes sense because 8-base numbers have digits representing exactly 3 bits, and the permission bits are grouped by 3. (This made a lot more sense on old PDP machines that used octal all around, especially in the machine code presentation, and were the original hotbed of Unix development. On Intel and ARM, hex numbers are common, so octals are not instantly recognized for what they are.)

Upvotes: 2

Related Questions