File Permissions Changing
Firstly, normal users can only change the permissions of a file (or directory) if they own it. The owner of a file can be found by again using the "ls -l" command as shown below.
Changing a files permissions is done by using the "chmod" (change mode) command. This command is used in two ways, either using numbers or letters.
Using letters (symbolic codes)
First you have do decide what section of the permissions to set, this is done by specifying the first letter of the section, eg. "g" for group permissions. More than one section can given in a single command eg. typing "ug" will set the permissions for the files owner and all users thier group. Not specifying a section will be that all sections permissions will be changed.
Next you need to give the actual permissions you want to set. using a "+" in front of a permission bit will set it and using a "-" will unset it. For example "+w" will grant write access to the file. More than one permission bit can be given in a command along with different signs.
Here are some examples, that show make things clearer:
Current permissions | Command issued | New permissions |
---|---|---|
-rw-r--r-- | chmod +x filename | -rwxr-xr-x |
-rw-r--r-- | chmod u+x filename | -rwxr--r-- |
-rwxrwxrwx | chmod go-wx filename | -rwxr--r-- |
Using numbers (octal)
Most UNIX users find this method the quickest. All you need to do is refer to the first table on this page and look at the numbers for each permission bit. Then add together the values for the permissions you want the file to have. For example:
Add 400 for read access to the files owner (you).
Add 200 for write access to the files owner.
Add 40 for read access to all other users in the owners group
Add 4 for read access to everyone else.
Total = 0644 (it is best to always use four digits).
download file now