2

Both permission sets mean owner can read,write,execute; group and world can read,execute.

I expect 4755 to be r--rwxr-xr-x, but instead it is -rwsr-xr-x.

What is it?

Copying my comment to StephenKitt below

I've been visualising the permissions as literal bits. So that 755 is 111101101, But now we have a 100 in front of those -- so now 100111101101 which is somehow combined to put an 's' in that first field. It's not an AND because 7&4 is 4, and in fact 7 is as high we can go. So clearly my visualisation/expectation is astray.

2
  • 3
    Does this answer your question? Understanding UNIX permissions and file types Aug 21, 2020 at 19:24
  • @StephenKitt Not entirely. I've been visualising the permissions as literal bits. So that 755 is 111101101, But now we have a 100 in front of those -- so now 100111101101 which is somehow combined to put an 's' in that first field. It's not an AND because 7&4 is 4, and in fact 7 is as high we can go. So clearly my visualisation/expectation is astray. Can you see where? Aug 21, 2020 at 20:05

2 Answers 2

2

Your binary visualisation is correct, but your character visualisation isn’t (and that’s fine, it’s a bit complicated).

The first three bits are mapped as character variations in each of the character triplets which follow:

  • the topmost bit, setuid, is mapped to the executable location of the user permissions, as follows:

    • - if neither the executable bit nor the setuid bit are set;
    • x if only the executable bit is set;
    • S is only the setuid bit is set;
    • s if both bits are set;
  • the second bit, setgid, is likewise mapped to the executable location of the group permissions, again using -, x, S and s;

  • the third bit, the sticky bit, is mapped to the executable location of the “other” permissions, but using -, x, T and t.

Thus the twelve bits fit in nine characters:

       11          10           9
        |           |           |
 8  7   6    5  4   3    2  1   0
 r  w  x/s   r  w  x/s   r  w  x/t
1

You get the same thing represented differently. The 4755 is permission where: 4: means that the binary will be executed as the owner (usually root), you can refer to man setuid command for more information 7: means that the file can be written to, read by and executed by the owner 5: that the group can read and execute 5: means that any user can read and execute (it should be rx in your example)

The rwsr means that the uid is set to the user (it can be also set to the group).

3
  • But why isn't it srwxrwx? See my comment to Stephen Kitt's comment above. Aug 21, 2020 at 20:13
  • The s is visually laid on top of the x so that the symbolic permission bits can continue to fit in nine characters Aug 21, 2020 at 20:44
  • I've just said is the same representation of the same.
    – nethero
    Aug 22, 2020 at 4:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .