Unix/Linux file permisions

Permissions are usually represented as letters or numbers depending on what you are doing they have the same meaning.

The below are the basic permissions. Notice how the number 3 is missing well it will make sense shortly.

Meaning Number Letter
No Permissions 0
Execute 1 x
Write 2 w
Read 4 r

(Note: there are actually more permissions such as t, T, s, S and another x but this is just general information. I will add advanced topics latter)

Unix/Linux has 3 category of users that can access files they are the owner/user, group, and others. you will see this when you use the command:

$ ls -l    // this will list non-hidden files in a directory
$ ls -al   // This will list all files in a directory including hidden. 
$ ls -l total 760 
drwxr-xr-x 2 kirk www-data 4096 May 31 12:15 test 
-rw-r--r-x 1 kirk kirk 6633 Jun 2 15:23 test_1.php 
-rw-r--r-- 1 kirk kirk 413 Jun 2 08:18 test.js 
drwxr-xr-x 2 kirk kirk 4096 Jun 2 15:32 test_xls

There the first section has 10 places the first one usually has a ‘-‘ for a regular file ‘d’ for a directory and ‘l’ for a symbolic link. There are others but they are for advance uses.
The 2nd through 4th position show the user/owners permission it will display one of the following in each of the 3 positions for the user/owner ‘-,x,w,r’.
This will continue for the groups permission the next 3 positions and the others permissions in the last 3 positions.

 

Below is an example of a directory
Type USER/OWNER GROUP OTHERS
1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
d r w x r x r x
directory Owner
Yes
read
Owner
Yes
write
Owner
Yes
execute
Group
Yes
read
Group
No
write
Group
Yes
execute
Other
yes
read
Others
No write
Others
Yes execute
 
Below is an example of a regular file. The user/owner has full control, the group can only write to the file, others can do nothing
r w x w
Regular File Owner
Yes
read
Owner
Yes
write
Owner
Yes
execute
Group
No
read
Group
Yes
write
Group
No execute
Other
No
read
Others
No
write
Others
No
execute

Now we know what each letter and number represent and that there are 3 permission categories (User, Group, Others) that we use to allow access to our files.
Now back to the missing number 3. Computers do math using binary(0 and 1s) and we understand it better if we use octal (0 through 7) and you will see this below.
Remember 0 means no permission, 1 means you can EXECUTE a file, 2 means you can WRITE to a file, and 4 means you can read a file. If you are paying attention you noticed that the order is opposite from what is displayed by the ls -l command (rwx) or is it….
Binary like decimal have the smallest number is on the right and they get bigger as you move to the left

Binary 00000001  00000010  00000100
 octal 1  2  4
 symbol x  w  r

Now I will Reverse that table and expand it to include the 3,5,6, and 7

Binary 00000111 00000110 00000101 00000100 00000011 00000010 00000001 00000000
Octal 7 6 5 4 3 2 1 0
Symbol xwr wr xr r wx w x
The Math 1+2+4 2+4 1+4   1+2      

As you can hopefully see that the numbers combine for more or permissions. Another way to look at it is to ignore the first zeros in the binary and think of it as three light switches. The switches are off when one a O (zero) and on when 1 (one). Here is my switchboard image maybe it helps maybe not

switchboard

Categories: System Administration