in unix/linux sistem it is easy for us to define directory or file permission. there are 3 options : read, write, execute. these options are represented with binary number rwx, respectively for read, write, execute. there are also 3 user type/level exist : user, group, other. user means the specific user logged in the system which is also the owner of the file / directory, group mean several user that has been defined on one group name, and other represent any user exist or the whole world.
each file/directory in unix/linux will be labeled by specific permission, such as drwxrwxrwx.
to see this permission label just type command
and you will get the list of your files and folders plus its permission, owner, and date label.
In the first line (leftmost) u will see permission label such as
drwxrwxrwx or maybe
according to your own file permission.
for example we have
here is the explanation :
d:filetype ,d is for directory if its not specified it means that file isn’t directory
first rwx: “user” permission
second rwx: “group” permission
third rwx: “other” permission
so in example above we have directory file that permits anyone from user, group, and other to read, write/modify, and execute the file/directory.
to modify this parameter we can use chmod command.
for example u want to add read permission to group
u can type this command
chmod g+r filename/directoryname
chmod g+r index.php
add write permission to user
chmod u+w filename/dirname
add execute permission to other
chmod o+x filename/dirname
you are free to combine above commands, for example you want to add read, write, and execute permission to all user, you can type
chmod ugo +rwx filename/dirname
You can also use number format in chmod command.
the number format command contains three number from 000 to 777 to be set after chmod, followed by filename. for example
chmod 775 index.php
see the 775
the largest/leftmost number is for user
the middle number is for group
the last/rightmost number is for other
while each number represent read, write, execute in binary format
read, write, execute = 7
read, write, – = 6
read, – , execute = 5
read, – , – = 4
– , write, execute = 3
– , write, – = 2
– , – , execute = 1
– , – , – = 0
so by command
chmod 644 index.php
you give user permission to read, write group permission to read other permission to read and the permission for index.php will be rw-r-r- it is the same with entering chmod u+rw, g+r, o+r index.php