## Understanding and using Permissions

by pbharris
(Transferred from Wiki by Peter)

This was posted by otheos at www.techimo.com and he kindly gave me permision to reprint it here
Ok, one of the things most people get confused about is permissions. So here's an extract from my notes to help everybody remember once and for all ALL permission settings:

You remember, permissions are changed by:
Code:
chmod 0OGW filename
so for example you'd type:
Code:
chmod 0755 myfile
Now how are these numbers worked out?

The 0OGW are the 4 values that took 0755 in the above example.
The first 0 is for something else, leave it as ZERO for now.
The second, O sets permissions for the owner of the file
The third, G sets permissions for the group
The last, W sets permissions for the world (i.e everybody else).
Now each of these can have a value from 1 to 7. It is very simple:
Code:
1 = x -execute
2 = w -write
so 0444 means allow everybody to read etc.
now if you start adding you get combination permissions:
Code:
3 = 1+2 = wx -write/execute
5 = 4+1 = rx -read/execute
6 = 4+2 = rw -read/write
7 = 4+2+1 = rwx -read/write/execute
So it's only the primary values that can be added to form the remaining combination, so 6 can only be 4+2 and not 3+3 as it is meaningless (it is obvious but just making sure )

So if you want to set permissions for a file to be rwx for the user but only rx for the group and only r for the world then you'd say...
Code:
chmod 0754 myfile
or
Code:
chmod 754 myfile
leaving the first 0 out just making sure you're not messing with anything else.

I hope this helps.