File permissions are the attributes on a given file or directory that determine what actions a user can perform on that file or directory. The same rules and commands apply across all three of Unix, Linux and Mac due to a shared heritage.
If you open Terminal and issue the ls -al command this will give you long listing of the files and folders with the current working directory and its output should look familiar to that seen in the picture below:
The ls -al command shows the User that owns that file and which Group also has ownership of the file. As you can in the picture above, the User “Steven” and the associated Group “Steven” own most of the files, which is to be expected as this is Steven’s Home folder.
In Unix the permissions are split up into three main parts, first the User who usually was the original creator of the file/folder and is often referred to as the owner, then secondly the Group that owns file/folder and again is usually the group which the user is a part of and thirdly Others which is everyone that is neither the owner or part of the owning group. The diagram below shows this in more detail:
chmod 750 /example/file
where chmod is the command
750 represents the file permissions to set
/example/file is the absolute path to a given file or folder.
Each one of the three numbers represents the permissions for one of the three parts seen early i.e. User, Group and Others.
Lets just look at the first number which represents the User. If we convert 7 into binary we get 111, which corresponds to Read, Write and Execute. So the User has full access.
The second number represents the Group. Again we convert 5 into binary we get 101, which represents just Read and Execute but no Write access.
The last number represents the permissions for the Others. Not surprising in this example that 0 in decimal is just 000 in binary which represents no access i.e. no Read, Write or Execute.
Using three decimal numbers with the chmod command to set/modify file permissions is one approach to using the chmod command known as Octal mode due to fact it allows for eight different modes. Another way of using the same chmod command to set/modify permissions is called Symbolic mode as it utilises symbols such as u,g,o and r,w,x.
I will explain the Symbolic approach in more detail in Part 2 which you can read (here).