Hope this will help you to understand different file permissions and how to changes the permission of a file or directory in a UNIX/LINUX system.
Syntax;
chmod [numeric combination] [filename]
here [numeric combination] is created using the following criteria.
|
Owner (User who owns the file.) |
Group (Group that owns the file) |
Anybody (Other) |
non |
0 |
0 |
0 |
read |
4 |
4 |
4 |
write |
2 |
2 |
2 |
execute |
1 |
1 |
1 |
if you want to make your file read only by owner, then use
chmod 400 filename
if only executed by others
chmod 001 filename
if read/write by the owner and only read by everyone else
chmod (4+2)(4)(4) file
which is;
chmod 644 filename
With this if all need executable rights
chmod (4+2+1)(4+1)(4+1) file
that’s it;
chmod 755 filename
This can also be calculated in a more professional way.
when we are checking the permissions of files using “ls -l” command in the terminal we get a results which looks like “– rwx r-x r– file “.
this can be interpreted as;
- rwx r-x r-- file
--111 101 100
here;
r read
w write
x executable
- non
Where now when we convert each set binary digits to decimal,
Binary |
Decimal |
000 |
0 |
001 |
1 |
010 |
2 |
011 |
3 |
|
Binary |
Decimal |
100 |
4 |
101 |
5 |
110 |
6 |
111 |
7 |
|
We get the numeric values we wonted. In this case its 754
So we have to use the command.
chmod 754 file