All About File Permissions

This article explains how file permissions work, so you can set them correctly rather than copying numbers from a forum post.
Who Permissions Apply To
Every file and folder on a Linux server has three sets of permissions, for three categories of people:
- User is the account that owns the file, normally you.
- Group is the group that account belongs to.
- World is everyone else, including anonymous visitors to your website.
What Can Be Permitted
Each category can be granted any combination of three things:
| Permission | On a file | On a folder | Value |
|---|---|---|---|
| Read | View the contents | List what is inside | 4 |
| Write | Change or delete it | Add or remove items | 2 |
| Execute | Run it as a program | Enter it and reach what is inside | 1 |
How the Numbers Work
The three-digit number you see in a control panel is one digit per category, in the order User, Group, World. Each digit is the total of the values above.
So 7 is 4 plus 2 plus 1, meaning read, write and execute. 5 is 4 plus 1, read and execute but not write. 6 is 4 plus 2, read and write but not execute.
Reading 755 from left to right: the owner can do everything, the group can read and enter, and everyone else can read and enter.
The Values You Actually Need
| Value | Used for | Who can do what |
|---|---|---|
755 |
Folders | Owner full access, everyone else can read and enter |
644 |
Files | Owner can edit, everyone else can read |
600 |
Configuration files with passwords | Owner only, nobody else at all |
777 |
Nothing | Anyone can change it |
Why 777 Is a Problem
777 grants write access to every user on the server. On shared hosting that includes people who are not you. A writable file can be replaced with malicious code, which is one of the more common ways a site is compromised. Many servers refuse to serve 777 files at all and return a 500 error instead, which is why the permission that seems to fix everything often breaks things instead.
If something only works at 777, the real problem is ownership rather than permissions, and your host can correct it.
When Permissions Are the Cause
A 403 error usually means permissions are too strict for the server to read the file. A 500 error can mean they are too loose. Upload and save failures inside an application usually mean a folder it needs to write to is set to 755 when it needs 775.
Next: How to Change File Permissions in cPanel covers setting them.