chmod command is one of the useful commands in user and file management (especially script files). Here we are going to explain to you chmod 775, 755 & File permissions
File Permissions in Linux using Chmod
As you know the file system of linux has a file access and control mechanism which determines how and who can access a file stored in a linux system. This mechanism is based on two parts i.e. namely Classes and Permissions.
Classes determines who can access the files while Permissions decides how the file can be accessed to the user.
Types of Classes in Chmod
Three types of classes exits in linux i.e. Owner, Group, Others.
The owner is the creator of files/folder in Linux. By default, all the files and folders you create are owned by you, until you change the permissions manually.
The Group consists of multiple users who share the same permissions and user privilege.
Others mean the general public.
Permission Types in Linux
Next is permission , which are of three types based on a file or Folder, which you can either read, write or execute.
Read:- One can read a file but they can’t modify the contents. In the case of Folder, you can see the files inside Folder, but you can’t delete or add files into the folder.
Write:- Here you can modify file contents & in Folder, you can delete and add files into the folder.
Execute:- This permission allows one to run a file (mainly script).
If you combine the use of class and permission, you can control users on how they can access a file and what actions they can do or what they should not.
This can be understood by an example i.e. Owner has all the permissions (read, write and execute) to access a file. So if aren’t the owner of file /folder then you have to change the permissions to get the owner access to the file. The ownership of a file can be changed to any user as per requirements. The web server may won’t allow you to upload a file , in this case you are not having the enough permissions to add a file in a folder.
Chmod Number assignment
Now I expect you got the basic concept of classes and permissions , so we can go forward to the number i.e. “775” & “777”.
The file and folder is having a 8-bit data that controls the permissions mechanism. The basic binary form is “000” which means no permissions to any form.
As you set the “Read” permission , it adds 4-bit data which makes it “100” or a 4 in the usual decimal format.
Granting a write permission adds 2 bit data i.e “010” or 2 in decimal form.
Adding a “Execute” permission adds 1-bit to the data, which will result in “001”, or “1” in decimal form.
Numbers assigned to Read , Write & Execute
In other words
Read is equivalent to ‘4’.
Write is equivalent to ‘2’.
Execute is equivalent to ‘1’
So as u decide to set permissions , we have to add the numbers. For example if we set permissions to read and write , then its like 6 (4 + 2) for the permission. For read, write and execute, we will use ‘7’ (4 + 2 + 1) for the permission. Here’s the different permutation:
Chmod All Combinations
0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute
Using the numbers you can grant permissions to a file and add the numbers accordingly. So just understand this the three digits are “777”. First digit is for Owner, second or Group and third digit is for Others. If you assign “777” for a user then you can give all permissions for a file to all users.
Permissions it provide
It is used in web server. The owner of file has all the permissions but all two i.e. Group and Others have permission to read and execute,they can’t make changes to the file.
This number provides all the permissions of file to all three types of users. Every user can read , write and execute the file. It allows the users to add any type of code to your file. This is mainly applicable to the images in a website.
The owner can read and write while every other can only read it. No other can execute the file too.
The owner can read and write but can’t execute the file. Everyone except owner can read and execute but they can’t modify the file.
Setting File Permissions in Command Line
Linux lets you set all the file permissions by right click on the folder and by selecting “Properties”. The permission tab will let you assign permissions to the Owner , Group & Others.
The other way is terminal , where you can change the permission via Chmod. If you use chmod 777 that means you assigned all the permissions i.e. to make file readable, writable and executable by everyone.
chmod 775 /path/to/file
chmod command uses & Explanation
chmod is a command to change permission of a file. It stands for change mode. The number “775” is to provide permission to the file. There are three type of permissions.
r stand for read .its value is 4.
w stand for the write.its value is 2.
x stand for the execute.its value is 1.
If you assign a user 7 , then you are giving them read, write and execute permission to the user. The remaining part is 75 , which is explained here.
Example to Understand Chmod 775
If you enter a command ls -la or ls -li or ls -l , any of these commands will show all the files like this.
drwxr-xr-x 2 amiss amiss 4096 Jan 29 09:48 Templates
Here d stands for directory as templates is a directory.
now rest remaining 9 character.
The first 3 characters are owner means whom created this file , so he has all the permissions i.e. rwx (read , write , execute).
The next 3 characters is for group. The group can have one or more users whom are giving permission for a file as decided by you. The group has execute and read permission but they can’t write it.
The last is for other users i.e. permission for the read and execute.
So basically if you do 775 , then you are assigning same permissions to the owner , group and other users for a particular file which is written above.
Command for change the file permission in Linux – Chmod 775 syntax
chmod 775 filename
Hope the article helps you to understand the concept of permissions in a Linux system and the meaning of “777” & “775”.