Secret of file and folder permissions in ubuntu
Saturday, May 17, 2014
Permissions are also very very simple! but important. In ubuntu refer to a just three digit numbers. You will normally see 777 or 755 or 700. Those 3 digits numbers says what permissions has a user to a specific file or folder.
For example the 777:
The number 7 is the highest level which means the full control of a specific file (or folder)
The first 7 (777) is the permission of the owner of the file (or folder) has.
The second 7 (777) is the permission that group own the file (or folder).
The third 7 (777) is everybody else in the world that connects to that machine.
So, how do you get to this numbers 777 ??
The first is the number 4, so if you have a 4, you have only Read permissions. Basically if I say 774 means that everybody else will have the ability to read a file but nothing else.
Next you have 2 which is Write, so permission to write and finally you have 1 which means Execute.
Very important to know is that normally in a Server environment you have PHP files that are scripts and therefore you need to give the Execute permission in order to that specific script to execute.
Lets say I want the owner to have a full permission and control (Read, Write and execute), next I want all users to have a full control (Read, Write and execute) but I don’t want everybody else to Write files so I will give them only Read and Execute permissions. In this case the three digit numbers will be 775.
The command to change the permission is:
sudo chmod 777 file_name
When its a folder we just need to add -R (Recursive) otherwise will not change the permission to the files in the folder:
sudo chmod -R 777 folder_name
Lets say I want to change the permission of everybody else, I will just type:
sudo chmod 775 file_name
In the case of symbolic links, if the system provides, change the owner and group of the symbolic link instead of those of its destination.
-R Apply changes recursively to the specified directories and files and sub-directories included.
Example:
Set the user azad as the new owner of the file:
chown -R azad /home/mahedi/file
Set the user tony as the new owner of the file /home/mahedi/file and assigns the sales department:
chown tony:sales /home/mahedi/file
Backwards Compatibility, separating the name of the owner group name with a dot (.) Instead of a colon (:), however not recommended
chown elab.products /home/mahedi/file
Labels: HOW-TO
Post a Comment