How to work out permissions

By numbers

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:

permissions are changed by:

chmod 0OGW filename

So for example you'd type:

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:

1 = x -execute
2 = w -write
4 = r -read

So 0444 means allow everybody to read etc.

If you start adding you get combination permissions:

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...

chmod 0754 myfile
or
chmod 754 myfile

Leaving the first 0 out just makes sure you're not messing with anything else.

-author otheos

 

By rwx

I find it to be much more newbie friendly to use rwx.such as chmod go +rx file. Giving the group and the owner read and executeable access. Then you can easily see who get's what permissions without doing aritimetic every time. with:

g = group
o = owner
w = world (everyone else)

then

+r for read
+w for write
+x for execute

chmod gow +rwx file_name gives all permissions to all users.

This is how it was being taught to engineers at purdue that weren't even fluent using windows, to learn the basic unix commands, so to me it seemed quite newb friendly, as rwx are easily recognizeable as read, write and execute, this is also how they show up in an ll, making it a little easier to assign permissions quickly.

-author krohnjw