A plugin update fails, an upload throws a 403, or a script refuses to run. Usually the cause is a file mode, and learning how to change file permissions in Linux properly takes about ten minutes. You need one command, chmod, and two numbers: 755 and 644.
Quick Answer: Run
chmod 644 file.txtfor a normal file andchmod 755 folderfor a directory. 644 lets the owner read and write while everyone else only reads. 755 adds the execute bit, which a directory needs before anyone can open it. Confirm the change withstat -c '%a %U %n' file, and never "fix" a problem with 777.
Last verified: October 2026, against Ubuntu 26.04 LTS and 24.04 LTS, the GNU coreutils 9.12 manual and WordPress 7.x.
Hostaccent's engineers resolve 20 to 30 client issues every day, and in that queue permissions break more sites than any other Linux topic. This guide is those fixes, in the order we run them.
How Linux File Permissions Work
Every file and directory has three sets of permissions, for its owner (u), its group (g) and everyone else (o), each with three switches: read (r), write (w) and execute (x). ls -l shows them as nine characters after the file type:
bash-rw-r--r-- 1 site www-data 3120 Oct 12 09:14 index.php drwxr-xr-x 5 site www-data 4096 Oct 12 09:14 wp-content
A leading - means a file, d a directory, then owner, group and others.
File permission numbers explained
Numeric (octal) mode adds up three values per set: read is 4, write is 2, execute is 1. So 7 is rwx, 6 is rw-, 5 is r-x, 4 is r-- and 0 is nothing. Three digits, always in owner, group, others order.
| Mode | Letters | Who can do what | Typical use |
|---|---|---|---|
| 644 | rw-r--r-- | Owner reads and writes, everyone else reads | PHP files, CSS, images |
| 755 | rwxr-xr-x | Owner does everything, others read and enter | Directories, shell scripts |
| 600 | rw------- | Owner only | SSH private keys, .env files |
| 777 | rwxrwxrwx | Anyone can change anything | Almost never |
chmod 755 vs 644 meaning, in plain words
As of October 2026, the standard web-server baseline on Linux is still 755 for directories and 644 for files. A 755 directory lets anyone enter and list it, but only its owner can add or delete files inside. A 644 file lets anyone read it, but only its owner can change it. Execute on a directory simply means "may enter", which is why folders need 755 and plain files don't.
Do I actually need to memorise the numbers?
No. Symbolic mode uses letters and touches only what you name: chmod u+x deploy.sh adds execute for the owner and nothing else, while chmod 744 deploy.sh overwrites all nine bits.
How to Change File Permissions in Linux With chmod, Step by Step
Check the current mode, apply the new one, then confirm it stuck. You must own the file or use sudo.
- Check the current state.
stat -c '%a %U:%G %n' wp-config.phpprints something like644 site:site wp-config.php: mode, owner and name on one line. - Apply the mode, numerically or symbolically:
bashchmod 644 index.php # set exactly rw-r--r-- chmod 755 uploads # directory baseline chmod u+x backup.sh # add execute for the owner only chmod go-w config.ini # remove write from group and others chmod u=rw,g=r,o= .env # spell out 640
- Copy a known-good mode when you're unsure:
chmod --reference=index.php new.phpgives the new file exactly the same bits. The GNU coreutils chmod manual lists every option. - Verify. Run
statagain, then reload the page. A correct mode that still fails points to ownership or a parent directory.
Only a file's owner or root can change its mode, and that's the usual reason chmod fails with "Operation not permitted". Prefix the command with sudo, or act as the owning user with sudo -u site chmod 644 file. As of 2026 the rule is identical on Ubuntu 26.04 LTS and 24.04 LTS. Locked out of root entirely? Reset the root password safely first.
Pro Tip: Use
chmod -cinstead of-von big jobs. It prints only the files it actually changed, so the output doubles as a record of exactly what was wrong.
Still seeing the WordPress problem?
Share the error, affected page, and the checks you completed. Your WordPress site can stay with its current hosting provider.
Recursive chmod on a Directory Without Breaking Your Site
Never run chmod -R 755 or -R 644 across a site folder. Set directories and files separately with find.
Search "recursive chmod directory linux" and the first answer is usually chmod -R 755 /var/www. Nothing errors, but every PHP file and image becomes executable. Reverse it with -R 644 and every directory loses execute, so nobody (the web server included) can enter them: the classic site-wide 403.
The safe version:
bashcd /var/www/example.com find . -type d -exec chmod 755 {} + find . -type f -exec chmod 644 {} +
The + batches thousands of paths per chmod call; the older \; ending starts one process per file and drags on large sites.
A safe recursive permission reset for a typical PHP site in 2026 is two find commands that usually finish in seconds: directories to 755, files to 644. Running chmod -R with a single number is the most common way to turn a working site into a 403, because files and directories need different modes.
The one-line shortcut is chmod -R u=rwX,go=rX .. Capital X adds execute only to directories and files that already had it, so a clean tree lands on 755/644.
Insider Insight: Unlike
rm, GNU chmod does not protect/by default. Add--preserve-rootto recursive chmod in scripts, and snapshot modes first withfind . -printf '%m %p\n' > perms-before.txt.
WordPress Correct File Permissions and the Ownership Trap
WordPress correct file permissions are 755 on directories, 644 on files and tighter on wp-config.php, provided the right user owns them.
| Path | Mode | Why |
|---|---|---|
| All directories | 755 | Web server enters, owner writes |
| All files (.php, .css, images) | 644 | Readable, writable by owner only |
| wp-config.php | 600 or 640 (440 if never edited) | Holds the database password and salts |
| wp-content/uploads | 755 | Must be writable by the user PHP runs as |
| .htaccess (Apache) | 644 | WordPress rewrites it when permalinks change |
These match the official WordPress hardening guide, which suggests 440 or 400 for wp-config.php if nothing edits it.
Across the 4,000+ sites Hostaccent has migrated since 2016, the pattern we see most after a move is wrong ownership, not a wrong number. Files restored as root stay owned by root, PHP-FPM runs as the site user, and uploads fail even though every mode reads 755 and 644. In our experience, one chown beats any amount of chmod.
On cPanel, PHP runs as the account user, so that user should own public_html (a proper cPanel server setup handles this). On a hand-built Nginx and PHP-FPM stack, match the owner to the pool's user = line, and use groups when accounts share files, as in adding a user with the right groups.
The Owner-Mode-Path check
Our team works every permission ticket in the same order:
- Owner. Does
statshow the user PHP or your app actually runs as? - Mode. 755/644, with secrets at 600 or 640?
- Path. Can that user enter every parent directory?
namei -l /var/www/example.com/wp-content/uploadsprints each folder on the way down, so one locked 700 directory near the top stands out instantly.
The path step also explains many Let's Encrypt webroot failures, where a parent folder blocks the challenge file. See Certbot renewal failed fixes for that case.
Common chmod Mistakes and What to Do When It Still Fails
If chmod ran cleanly and the problem remains, look past the mode: a rejected 777, an immutable flag, a mount option or a security module.
- 777 makes it worse. Many PHP handlers on cPanel and shared servers refuse world-writable scripts and return a 500 error. Fix the owner instead.
- "Operation not permitted" even with sudo. Run
lsattr file. Animeans immutable; clear it withsudo chattr -i file. FAT, NTFS and exFAT drives ignore chmod, so setuid,gidandumaskwhen mounting. - SSH keys rejected. OpenSSH ignores a private key others can read: use
chmod 700 ~/.sshandchmod 600on keys. If SSH instead warns that the host key verification failed, that's a fingerprint issue, not permissions. - SELinux on RHEL-family servers. The wrong context blocks correct modes. Check with
ls -Z, reset withrestorecon -Rv /var/www.
One 2026 change catches people out. Ubuntu 26.04 LTS, released on 23 April 2026, ships the Rust-based uutils rewrite of the core utilities by default, so chmod there is no longer the GNU binary (GNU still provides cp, mv and rm). The commands here work the same, but run chmod --version before debugging an odd script.
Key takeaways
- 755 for directories, 644 for files, 600 or 640 for secrets.
- Never apply one number recursively; split with
find. - Check owner and parent directories before loosening a mode.
- 777 signals a wrong owner; it is never the fix.
Your Next Step: A VPS Where You Control Every Permission
Now that you know how to change file permissions in Linux, and that ownership breaks as many sites as the numbers do, you can keep patching modes on hosting where you can't see who PHP runs as, or move to a server where you hold root and run the Owner-Mode-Path check in a minute. A Hostaccent Linux VPS gives you full root access, free 30 Gbps DDoS protection and 24/7 support from our own engineers, and the Standard plan is $12.00/mo, renewing at that same price. One honest caveat: no cPanel or Plesk licence is included, so a panel costs extra. If that suits you, start on the Standard plan at $12.00/mo, with a 30-day money-back guarantee behind it.
Frequently Asked Questions
Is chmod 777 ever safe on a web server?
Almost never. 777 lets every account and process on the machine change the file, so one compromised plugin or neighbouring user can rewrite your code. Many PHP handlers also refuse world-writable scripts and answer with a 500 error, so 777 often fails to fix the problem it was meant to solve. If something needs write access, give it to the right owner or group with chown and keep the mode at 755 or 644.
How to change file permissions in Linux without root access?
You can change permissions on any file you own, and you don't need sudo for that: chmod 644 myfile works as your normal user. For files owned by someone else, chmod returns "Operation not permitted", and there's no way around it short of sudo rights or asking the owner. On shared hosting, the control panel file manager runs as your account, so it can change anything inside your own home directory.
What is the difference between chmod and chown?
chmod changes what each audience may do (read, write, execute), while chown changes who the owner and group are. That's why a 644 file can still be unwritable for your app: the mode is right but the owner is wrong. A typical repair runs both, for example chown -R site:site public_html followed by the two find commands that reset directories to 755 and files to 644.
What permissions should wp-config.php have?
Use 600 if PHP runs as the same user that owns the file, which is normal on cPanel and per-site PHP-FPM pools. Use 640 when the web server reads it through a shared group instead. The WordPress hardening guidance suggests 440 or 400 if you never edit it in place. Avoid 644, because the file holds your database password and secret keys, which should never be readable by every account on the server.
Why do I still get "Permission denied" after chmod 755?
Usually because a parent directory blocks the path. Linux checks execute permission on every directory from the root down to the file, so a single 700 or 750 folder higher up locks out the web server whatever the file itself says. Run namei -l /full/path/to/file to see each step. If those look fine, check ownership with stat, the immutable flag with lsattr, and the SELinux context with ls -Z.












Discussion
Have a question or tip about this topic? Share it below — your comment will appear after review.