r/eli5_programming • u/mutantSackboy4 Observer • Aug 29 '25
Question ELI5 the Linux sudo chmod numbers.
I know, I use Linux, I should be smart enough to know this stuff, right? But unfortunately I don't so I've turned to you fellas. I get 755, it's all for me and read-run for thee, pretty much, or something like that - but what about other numbers? Edit: changed "do" to "so" due to uncaught typo.
30
Upvotes
8
u/kevinb9n Aug 29 '25
It's an octal number. The digits represent "user", "group", and "others", and each digit is 4 for read + 2 for write + 1 for execute.
I never use those anymore, I do like `chmod ugo+rx` and such.
4
u/albujuk Aug 29 '25 edited Aug 29 '25
There are 3 Digits, User, Group, and Others.
Also there are 3 Permissions Read, Write, Execute their representation in numbers accordingly as the following 2²=4, 2¹=2, 2⁰=1
you can add them together to combine permissions.
e.g. 754 that means the user can read, write and execute. the group can read and excute only and others can only read.
4
u/Kqyxzoj Aug 31 '25
man chmodshould help.https://linux.die.net/man/1/chmod
2
u/michaelpaoli Aug 31 '25
Well, let's say you count on your fingers ... but ... only have three fingers.
And for the fingers, from right (least significant) to left (most significant), give them values, starting with 1 on right, then doubling for each finger after that, so, right to left, you have fingers of values 1, 2, and 4. So, finger up (active/on), or down (off/inactive) either counts, or doesn't, for their value - and you add up their values. You get a total of any whole number from 0 through 7. Great, that's octal - a 3 binary bits per octal (0 through 7) digit. Now you do 3 (or 4) sets of those, right to left, each group of 3 bits/fingers, give you one such octal digit. The least significant - 1 bit, is for "execute" - on it's allowed, of it's disallowed. Next is the 2 bit, it's for write - on allowed, off disallowed., and next is the 4 bit, for read, on allowed, off disallowed. That gives you also that rwx - or - character(s) in their place, indicate read, write, and "execute", if they're on or off, in a visual representation. or for numeric, octal, add up the 4's, 2's, and 1's place, each as set (add it) or not (don't add it), to get total from 0 through 7. Now do 3 sets of those, again, right to left. Rightmost (again, least significant), those are permissions for other/world. Next set is for group - permissions for the group that has group ownership of the file. And next set is for user - permissions for the user that owns the file. There's another group of 3 more bits for additional permissions (sticky, SGID, SUID) again rightmost / least significant - to left, but that's beyond ELI5 territory. And beyond that, there are yet more bits - they determine the type of file, e.g. is it a file of type ordinary file, or is it a directory, etc. - but again, beyond ELI5 territory.
See also (and beyond ELI5 territory): https://www.mpaoli.net/~michael/unix/permissions.html