Understanding how to read permissions info

Status
Not open for further replies.

CraftyClown

Patron
Joined
Apr 5, 2014
Messages
214
Hi guys,

I've had a bit of a struggle getting my head around permissions for a while now, but I think I'm mostly there.

I'm just wondering if there is a good resource that spells out in idiot speak how the numbers/letters/tick boxes on data sets etc, relate to one another?

For example; I understand that 0777 is effectively all the tick boxes for owner/group/other ticked, but I'm not quite sure how that would translate into (rwx-rw-x) etc

I also have a particular plugin that is saving certain files as rw-rw-rw, but I have no idea what number that would be (0664 etc) but I'm presuming it would be read and write tick boxes for all users, but no execution for anyone? Am I on the right lines?

I've attached a screenshot of how I have the permissions tick boxes on one of my data sets selected. Could someone tell me how that translates into the other formats and whether or not it is a safe selection for general use? I'm presuming it is.

Thanks in advance for any help. I really want to get this permissions thing cracked once and for all, as I understand it is essential to mastering Freenas
 

Attachments

  • Unix perms.jpg
    Unix perms.jpg
    35.4 KB · Views: 246

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Permissions are presented as user read/write/execute, group read/write/execute, world read/write/execute, in that order. Thus, permissions of rw-rw-r-- would allow the owner user, or anyone in the owner's group, to read and write to the file, and the world can only read (but not write).

When converting permissions in the form of rw-rw-r-- to numbers like 664, you need to convert binary to octal (base 8). If you're comfortable doing this, you can probably stop here--but if you were comfortable doing this, you probably wouldn't have asked the question. To do this, each group of three permissions (rwx) converts to one digit of the numeric code. An r has a value of 4, a w has a value of 2, and an x has a value of 1. Add these together in each group to get the corresponding digit. Thus, for rw-rw-r--, r (4) + w (2) = 6. This gives 6 as the first two digits (because both the user and the group have rw permissions), and 4 for the last digit (because world is read-only).

When converting numeric permissions to the individual flags, you'll go in reverse. Each digit represents one group of rwx permissions. For each digit, if it is >= 4, subtract 4 and set the 'r' flag. If the remainder is >= 2, subtract 2 and set the 'w' flag. If the remainder is >= 1, subtract 1 and set the 'x' flag. The remainder after you've done this should be 0 for each digit. As an example, let's convert permissions of 750 to the alpha flags. The first digit is 7. It's >= 4, so subtract 4 (leaving 3) and set the 'r' flag. The remainder is 3, which is >= 2, so subtract 2 (leaving 1) and set the 'w' flag. The remainder is 1, which is >= 1, so subtract 1 (leaving 0) and set the 'x' flag. The first set of flags is thus rwx. Now to the next digit, which is 5. That's >= 4, so subtract 4 (leaving 1) and set the 'r' flag. The remainder is 1, which is < 2, so don't set the 'w' flag and don't subtract 2. The remainder is still 1, which is >= 1, so subtract 1 (leaving 0) and set the 'x' flag. The second set of flags, then, is r-x. The third digit is zero, which means none of the flags are set. The full permissions, then, are rwxr-x---.
 

CraftyClown

Patron
Joined
Apr 5, 2014
Messages
214
Permissions are presented as user read/write/execute, group read/write/execute, world read/write/execute, in that order. Thus, permissions of rw-rw-r-- would allow the owner user, or anyone in the owner's group, to read and write to the file, and the world can only read (but not write).

When converting permissions in the form of rw-rw-r-- to numbers like 664, you need to convert binary to octal (base 8). If you're comfortable doing this, you can probably stop here--but if you were comfortable doing this, you probably wouldn't have asked the question. To do this, each group of three permissions (rwx) converts to one digit of the numeric code. An r has a value of 4, a w has a value of 2, and an x has a value of 1. Add these together in each group to get the corresponding digit. Thus, for rw-rw-r--, r (4) + w (2) = 6. This gives 6 as the first two digits (because both the user and the group have rw permissions), and 4 for the last digit (because world is read-only).

When converting numeric permissions to the individual flags, you'll go in reverse. Each digit represents one group of rwx permissions. For each digit, if it is >= 4, subtract 4 and set the 'r' flag. If the remainder is >= 2, subtract 2 and set the 'w' flag. If the remainder is >= 1, subtract 1 and set the 'x' flag. The remainder after you've done this should be 0 for each digit. As an example, let's convert permissions of 750 to the alpha flags. The first digit is 7. It's >= 4, so subtract 4 (leaving 3) and set the 'r' flag. The remainder is 3, which is >= 2, so subtract 2 (leaving 1) and set the 'w' flag. The remainder is 1, which is >= 1, so subtract 1 (leaving 0) and set the 'x' flag. The first set of flags is thus rwx. Now to the next digit, which is 5. That's >= 4, so subtract 4 (leaving 1) and set the 'r' flag. The remainder is 1, which is < 2, so don't set the 'w' flag and don't subtract 2. The remainder is still 1, which is >= 1, so subtract 1 (leaving 0) and set the 'x' flag. The second set of flags, then, is r-x. The third digit is zero, which means none of the flags are set. The full permissions, then, are rwxr-x---.

Thank you so much. That was incredibly helpful and makes reading permissions crystal clear
 
Status
Not open for further replies.
Top