Your WordPress site runs on a VPS, which means nobody else sets the file permissions for you. On shared hosting, the host locks things down by default. On your own server, every file sits under rules you control, and the wrong rules leave the door open. Get WordPress file permissions VPS owners actually need right, and most common attacks stop before they start.
Most WordPress hacks do not start with a clever zero-day. They start with a plugin that writes a file where it should not, or a theme file a visitor can edit through a request the server should have refused. Permissions decide which of those moves are possible. This guide covers the exact numbers to use, who should own each file, and the checks that prove the setup holds.
Why file permissions decide what an attacker can do
Every file and directory on your server carries three sets of rights: what the owner, the group, and everyone else can do. Each set allows reading, writing, or executing. When a file is world-writable, any process on the server can change it, including a PHP script planted through a vulnerable plugin.
On a typical Ubuntu VPS, the web server runs as the www-data user. WordPress needs that user to read every file and write in a few places: the uploads directory, and briefly during updates. It does not need write access to your theme files or plugin code, and it never needs it for wp-config.php. Handing out write access everywhere because an update failed once trades a small annoyance for a real hole. The WordPress security basics for VPS owners cover the wider checklist, but permissions are the layer underneath all of it.
WordPress file permissions VPS: what 644 and 755 actually mean
Two numbers cover almost everything: files get 644, directories get 755. The first digit is the owner, the second the group, the third everyone else. A 6 means read and write, a 5 means read and execute, a 4 means read only.
| What | Permissions | Who can write |
|---|---|---|
| All directories | 755 | Owner only |
| All files | 644 | Owner only |
| wp-config.php | 600 or 640 | Owner only |
| .htaccess / nginx config snippets | 644 | Owner only |
| wp-content/uploads (directories) | 755, group-writable if needed | Owner and web server group |
A directory needs execute permission so the web server can reach files inside it. That is why directories are 755 and not 644: without the execute bit, Apache or nginx cannot serve anything from that folder. Files do not need the execute bit, so 644 is right for them. This chmod 644 755 WordPress setup is the default for a reason. For the full background on how these numbers work, read Linux file permissions explained before you change anything.
Ownership comes before chmod
Permissions only make sense once ownership is right. WordPress files should belong to your deploy user, with the group set to www-data. That gives you full control over the code while the web server can read it through the group.
The command looks like this, run from your site root:
sudo chown -R deploy:www-data /var/www/your-site
sudo find /var/www/your-site -type d -exec chmod 755 {} ;
sudo find /var/www/your-site -type f -exec chmod 644 {} ;
Replace deploy with your own username and /var/www/your-site with your real document root.
WordPress file ownership www-data as the group is the setup most guides assume: the web server reads files through group membership, your SSH user keeps write access as the owner, and the web server cannot write to plugin or theme code. That last part is what stops a compromised script from rewriting your site.
Never run your site as root. A process running as root that gets compromised hands over the whole server, not just one site.
Lock down a live site in four steps
Do this during a quiet hour; it takes a few minutes.
- Back up first. Take a file backup and a database backup before you touch permissions. If a plugin relied on write access somewhere unusual, you want a way back.
- Fix ownership. Run the
chowncommand above so your user owns the files andwww-datais the group. - Apply 644 and 755. Run the two
findcommands to reset every file and directory to the safe defaults. - Tighten wp-config.php. Give it 600 so only the owner can read it:
chmod 600 wp-config.php. If your setup needs the web server to read it directly, 640 works too, sincewww-datais the group.
After step three, load your site and upload a test image. If pages load and the upload works, the basics are right.
wp-config.php and the files that deserve tighter rules
wp-config.php holds your database password and session secret keys. Anyone who can read it can connect to your database. That is why it gets 600, not 644. With 600, only the file owner can read it, and the web server still reads it fine when PHP runs as your user through PHP-FPM pools, or through the group with 640 when it runs as www-data. Getting wp-config.php permissions right is the single highest-value change in this guide.
Other files worth the same treatment:
- Backup archives inside the web root. A
.zipor.sqlfile in a public directory is downloadable by anyone who guesses the name. Move backups outside the document root, or delete them after downloading. - Environment files. If you keep a
.envfile for a companion app, set it to 600 and keep it out of the web root. - Log files. Error logs sometimes contain paths or database errors. They do not belong in a browser-accessible folder.
For the details this article skips, see how to secure wp-config.php and set WordPress file permissions.
The uploads folder needs write access, not open access
WordPress must write to the uploads folder every day: media uploads, thumbnails, and some cache files land here. That does not mean it should be 777, which lets any user on the server write anything into it.
The safe setup is 755 on the directories with group write where the web server needs it, or 775 on the uploads tree with www-data as the group. WordPress can then create new folders and files, while other users on the server stay out. That is how you secure WordPress uploads folder access without breaking media uploads.
sudo chmod 775 /var/www/your-site/wp-content/uploads
sudo find /var/www/your-site/wp-content/uploads -type d -exec chmod 775 {} ;
The second risk is what gets uploaded. A PHP file dropped into uploads and then executed would run with the web server’s privileges. Block that at the server level with an nginx rule that denies PHP execution inside the uploads directory:
location ~* /wp-content/uploads/.*.php$ {
deny all;
}
Add it to your server block, test with nginx -t, and reload. Even a successful upload of a malicious script can no longer run.
Mistakes that break your site or leave it open
The usual mistakes:
- chmod 777 to fix an upload error. This is the classic shortcut. It fixes the symptom and opens the folder to every process on the server. Look for the real cause instead: usually ownership, not the number.
- Everything owned by root. When files belong to root and the web server cannot read them, updates fail and media uploads break. Ownership by your deploy user with the
www-datagroup is the fix. - Recursive chmod on the wrong path. A typo in a
findcommand can reset permissions on the wrong directory tree. Always runpwdfirst, and test changes on a staging copy of WordPress on the same VPS when you are unsure. - Forgetting plugin-created folders. Some plugins create their own cache or data directories outside uploads. After a reset, check the plugin still works, and give only its folder the write access it needs.
- Leaving old backups in the web root. A backup from six months ago is a copy of your database and config sitting in public. Move it off the server or delete it.
Check your work before you move on
A setup you never verify is a guess. These three commands tell you whether the rules you set hold.
List every world-writable file. The result should be empty:
find /var/www/your-site -type f -perm -o=w
List world-writable directories. Only the uploads tree should appear:
find /var/www/your-site -type d -perm -o=w
Check the ownership chain down to your config file. If any directory in the path is world-writable, the file inside it is exposed:
namei -l /var/www/your-site/wp-config.php
Run these checks after the first setup, after every restore, and after any major plugin install. Permissions drift as plugins and updates touch files, and a five-minute check catches the drift before an attacker does.
Set 644 and 755 as the default, give wp-config.php 600, keep uploads writable but unable to run PHP, and verify the result. Most hacked WordPress sites never got this layer right.