Search Knowledge Base by Keyword
How to change permissions (chmod) of a file
Permissions are an important aspect of hosting your website. Permissions allow our servers to read or write your files. In addition, this also helps some files to be protected from being changed (as a result of writing or editing). This is a security measure. In cPanel, there are multiple ways to change the permissions of a file. In this tutorial, we will go through all the ways in which you can change these permissions.
Method 1 – Using cPanel File Manager
File Manager offers a convenient way to change the permissions in cPanel. To change the permissions of a particular folder within cPanel, follow these steps:
- Firstly, Log into the cPanel
- Click File Manager. This should look like below (highlighted)
3. Select a folder of choice within the file manager. There are multiple methods to go ahead and change the permissions. Let us look at them one by one:
Option 1: Locate the name of the folder (or file) for which you wish to change the permissions. In the below figure, we’ve selected the public_html folder, and then click the Permissions(with the key icon) button at the top right(third last button -highlighted in yellow). Here is how it looks like:
Option 2 : Choose the file name for you’d like to the change the permissions. Right click, and then change permissions from there. Have a look at the image below to understand what we mean.
Option 3 – Simply double click the numbers in the last column. Yes, these numbers are basically permissions coded as numbers.
Here is how to understand this better. The numbers, for instance, represent a combination of each unique permission. Also, the first of the three digits represents the permissions for the Owner. The second digit represents the Group. The third digit represents the World.
- Read is equal to 4.
- Write is equal to 2.
- Execute is equal to 1.
- No permissions for a user are equal to 0.
For those who aren’t aware, here is how these numbers work. You can set read, write, execute permissions for user, group and the universe(world) here. Then click Change Permissions. As a result of this action, your permissions will change.
Method 2 – Using FTP
Launch and connect an FTP client of choice (like FileZilla). After that, locate the folder that you’d like to change the permissions for. For instance, in the below case, we selected the folder 123wp. Here is how it should look in the image below
Once selected, right click on the desired folder, and click File Permissions and set the permissions that you’d like. Here’s a sample screen from FileZilla FTP client.
Here are the three types of users.
- Owner: You are the owner. This person has access to the cPanel.
- Group: This refers to the people on the server.
- World: This refers to the universe, or any visitor who is public.
Each row represents a permitted action for this file (or folder).
- Read means the user is allowed to view the file.
- Write means the user is allowed to edit the file.
- Execute means the user is allowed to run the file.
It is very important that Group and World are able to view your website files. However, there are some files that you may not want anyone to see. If you remove the check for Read under Group and World, then the file will not show in anyone’s browser (instead, visitors will see a 403 Forbidden error).In the File Manager, permissions are expressed as numbers. We are only concerned with 3 digits, so if you see 4 digits, then ignore the first one. Thus, 0755 is the same as 755.
The numbers represent a combination of each unique permission. Also, the first of the three digits represents the permissions for the Owner. The second digit represents the Group. The third digit represents the World.
Understanding the permissions better
- Read is equal to 4.
- Write is equal to 2.
- Execute is equal to 1.
- No permissions for a user are equal to 0.
Thus,
- Write and Execute without Read is equal to 3.
- Execute and Read without Write is equal to 5.
- Write and Read without Execute is equal to 6.
- Read and Write and Execute is equal to 7.
What is important, therefore, is to understand that your files should always carry the permissions 644 or 755. For most files, executable permission may not be required. However, in some cases, like when setting permissions for the wp-content folder of WordPress, you may need to grant this permission in order for WordPress to be able to upload images onto the folder.
However, folders must always be 755.
Also, there’s one more rule. Any files inside the cgi-bin folder must have 755 permissions.
But what’s the issue with these permissions?
The concern with giving executable permissions is that your files get exposed to hackers from outside your server who can then edit your files. Therefore, the last two digits should never be 2,3,6,7
Here is a table showing the numerical (and linux) representations of the permissions, and our recommendations around it.
2D Matrix | Numerical Representation | Linux Representation |
755 or 0755 Recommended! | drwxr-xr-x | |
644 or 0644 Recommended! | drw-r–r– | |
700 or 0700 | drwx—— | |
777 or 0777 Not recommended! | drwxrwxrwx |