How to Set File and Folder Permissions with chmod and chown
On Linux, two commands control who can touch a file: chmod sets the permissions (read, write, execute), and chown sets the owner. Get them right and your site runs cleanly; get them wrong and you see "permission denied" or a 500 error. The rules are simpler than they look.
You will need SSH access to use these.
The permission values worth memorising
- 755 for folders — owner full control; others can read and enter.
- 644 for files — owner can edit; others read only.
- Avoid 777 — it lets anyone write, and is a common security hole.
Step 1: Change permissions with chmod
Set a single file:
chmod 644 index.php
Apply the correct values across a whole site at once:
find /path/to/site -type d -exec chmod 755 {} \;
find /path/to/site -type f -exec chmod 644 {} \;
Those two lines set every folder to 755 and every file to 644 — the safe baseline for most websites.
Step 2: Fix ownership with chown
Files should be owned by the correct user (and web-server group). For example:
chown -R username:username /path/to/site
The -R applies it to everything inside. Wrong ownership is a frequent cause of upload failures and WordPress being unable to update itself.
Reading permissions at a glance
Run ls -l and you will see strings like -rw-r--r--. The first character is file/folder, then three groups of read/write/execute for owner, group and everyone. Once you can read these, diagnosing permission issues becomes quick.
Frequently asked questions
Something only works when I set 777 — is that okay?
No, and it usually signals an ownership problem in disguise. Fix ownership with chown so the right user owns the files, then 755/644 will work. Leaving 777 in place is a real risk.
What is the difference between the owner and the group?
The owner is the user who controls the file; the group is a set of users given shared access. For web files, the owner is your account and the group often includes the web server, so it can read what it needs.
Prefer clicking to typing?
On cPanel you can set permissions in File Manager — see checking and changing file permissions in cPanel.
Was this article helpful?