CheckWebSecurity Brand Logo

Article

wp-config.php permissions: the one file that should not be 644

Published 2026-11-23

wp-config.php permissions: the one file that should not be 644

Every WordPress site has one file that knows everything: the database password, the database user, the keys that sign admin login cookies. It is wp-config.php, and on a lot of servers it is sitting there with permission 644, which means readable by every user account on the machine. If you have never looked at that file's permissions, this article is a five-minute fix that removes an entire class of compromise.

The odd part is that 644 is the default. Upload a file over FTP and the server stamps it 644. Extract a WordPress zip and the files arrive 644. The WordPress.org file permissions handbook lists wp-config.php with an explicit correction next to it: the example table shows 644 for normal files and then 600 for wp-config.php, with the note that this file holds more secrets than anything else in the tree. Most guides (Jetpack's, Pressidium's, the handbook itself) agree on 600 or 640. And yet a walk through real servers finds the file at 644 more often than not, because nobody ever changed it from the default.

Here is what the file actually holds, why the read bit matters, and how to fix it without taking your site down.

What wp-config.php knows

Open the file and read it once, carefully. It is the clearest security inventory you will get from one page of PHP:

  • Database credentials. DB_NAME, DB_USER, DB_PASSWORD, DB_HOST. These are live credentials for the MySQL account that owns every post, order, and user record on the site. On shared hosting, that database server is often reachable from any site on the same box, so the password works from anywhere the attacker can run code.
  • The security keys and salts. AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY and their salted variants. These are not decoration. WordPress signs every authentication cookie with them, using hash_hmac in wp_generate_auth_cookie. Someone who has your salts and keys can forge a cookie that says "logged in as admin" and the server will believe it. No password guessing against the login form, no lockout, no failed-login log entries. The only remaining work is a small offline brute force over four characters of a password hash, which researchers at Trustwave demonstrated years ago and is measured in days, not centuries. This is the single worst thing in the file to leak.
  • The table prefix. wp_ by default, but if you changed it, the file states it. That prefix is the first thing an attacker wants for SQL injection payloads.
  • Sometimes, FTP credentials. On hosts that prompt for connection details when you update plugins, those details can end up saved in wp-config.php too.
  • Sometimes, WP_DEBUG and other flags. Less dangerous on their own, but a WP_DEBUG toggle in a readable file invites someone to flip it remotely if they get write access later.

So the file is a keyring. Database key, admin-session key, often filesystem key. Now think about what "readable by everyone" means for a keyring.

What 644 actually means

The three digits map to three audiences: owner, group, everyone else. 644 decodes as:

| Digit | Audience | Can read | Can write | |---|---|---|---| | 6 | Owner (you / the FTP account) | yes | yes | | 4 | Group (the owner's group) | yes | no | | 4 | Everyone else on the machine | yes | no |

The last digit is the one that should bother you. "Everyone else" is every shell user, every cron job, every backup agent, every process running under a generic web server user, on the whole server. Whether that is a real crowd depends on how the server runs PHP, and this is where most explanations get vague, so let me be concrete about the two common setups.

Shared PHP user (mod_php, or one php-fpm pool for all sites). In the old shared-hosting model, every site's PHP runs as the same user, typically www-data or apache. If one site on the box gets infected, the malware runs as that shared user and can open every wp-config.php on the machine, all of them stamped 644 "for everyone" to read. This is not a hypothetical chain; it is the standard way infections hop between sites on cheap shared hosting. Setting your config to 600 owned by your own account breaks that hop, because the shared web user no longer has permission to read your file.

Per-site PHP user (suexec, or a php-fpm pool per site). Better hosts run each site's PHP as that site's own account. Here 644 is less catastrophic but still wrong: the "everyone" bit means any other real account on the machine can read the file. Another tenant's shell account, a contractor with temporary FTP access, a cron script someone left running. 600 removes that whole audience with one command.

The honest summary: with proper per-user isolation, a 644 config usually does not get you compromised by a neighbor. But "usually" and "properly configured" are doing a lot of work in that sentence, and the fix costs one command. Defense in depth is supposed to be cheap. This one is.

One more reason: the file that gets served raw

There is a scenario where permissions save you even with no local attacker at all. Web servers do not hand out wp-config.php because PHP intercepts the request and executes the file, returning nothing. That interception depends entirely on the PHP handler being correctly wired for that specific filename.

Now upload a backup of the file as wp-config.php.bak, or edit a copy as wp-config.php~, or save it through some editor that leaves wp-config.php.save. The extension is no longer .php. The handler does not match it. Apache and nginx fall back to serving it as plain text, and the database password, salts, and prefix arrive in the browser of whoever asks. A 644 file is downloadable this way. A 600 file is not, because the web server user cannot read it either, and the request fails instead of leaking. The same logic covers a misconfigured server where the PHP handler breaks: with 600 the broken handler serves an error page, not your credentials.

This is why the fix below also includes deleting stray copies, and not just chmodding the original.

Check your file

Over SSH, from the WordPress root directory:

ls -l wp-config.php
stat -c '%a %U:%G %n' wp-config.php

The second form prints the mode, the owning user and group, and the filename in one line. What you want to see:

600 youruser:youruser wp-config.php

Or 640 if your host needs group access (more on that below).

While you are there, hunt for the copies that nobody remembers creating:

find . -maxdepth 2 -name 'wp-config*'

Every result that is not wp-config.php itself is either a backup someone made before an edit, a file a plugin left behind, or an artifact of a migration. Delete the ones you do not need. If you must keep one, it deserves 600 too, and ideally it should not live inside the directory the web server serves at all.

Fix it

One command:

chmod 600 wp-config.php

Load the site right after. If it loads, done. The most common failure after this change is not the mode itself, it is the owner: the file must belong to the same account PHP runs as, otherwise PHP cannot read it and the site goes down with a fatal error or a white page.

If the site breaks, check who PHP is running as and who owns the file:

ps aux | grep -E 'php|apache' | head
ls -l wp-config.php

On a host where PHP runs as your account (suexec or a per-site php-fpm pool), the file should be owned by your account. On a host where PHP runs as www-data, the file can be owned by www-data with mode 600, or owned by your account with mode 640 and group www-data. The 640 case is what the "or 640" in all those guides means: the group read bit exists so a different PHP user can still read the file, and the "everyone" bits are gone.

If you have no SSH access, you cannot chmod from a file manager panel in most shared hosting control panels, cPanel included. Ask the host to set it, or use their file manager's permissions dialog if it has one. The change is small enough that support teams do it without argument.

One honest warning: the fix is not permanent until it is part of your process. Move the site, restore a backup, or copy files over FTP with a different client, and the file can come back 644. Check it after any migration the same way you check the site loads after any migration.

Two adjacent hardening steps worth knowing

Move the file up one directory. WordPress looks for wp-config.php in the WordPress root and, if it is not there, exactly one directory above. This behavior is in wp-load.php and is long-standing. On servers where the web root is something like /home/user/public_html, you can move the config to /home/user/wp-config.php and it keeps working, sitting outside the published directory. The raw-download problem mostly disappears, because a request can no longer reach the file at any URL. This is one of the oldest and least used hardening moves there is, and the only reason not to use it is an unusual host setup or a plugin that assumes the file's location.

Rotate the salts if you suspect exposure. If the file sat world-readable for a long time, or if you found it served raw even once, changing the permissions closes the door but does not kick out whoever copied the keyring. The salts are the part that forgives nothing: regenerate them via the WordPress.org salt generator, paste the new block into the config, and every existing cookie becomes invalid, which signs every user out. Do it in a quiet window and say so on the site if you have staff or customers logged in all day. Do not regenerate salts as a routine "just in case" without a reason, because the logout wave annoys people; do it when there is evidence of exposure.

A checklist you can run in ten minutes

  1. ls -l wp-config.php on each site. Anything with a 4 in the last position (world read) is wrong.
  2. chmod 600 wp-config.php (or 640 if the host needs group read).
  3. find . -maxdepth 2 -name 'wp-config*' and delete every copy that is not the real file.
  4. Confirm the site loads. If not, fix the owner before touching the mode again.
  5. Same check after the next migration or restore. The default follows the files around.

None of this touches the database, the theme, or any plugin. It is one mode bit and one owner, and it retires the file with the most secrets on the server from the "everyone can read" pile.

CheckWebSecurity's external scan looks at what your web server actually exposes: readable configuration files, leftover backup and editor copies, directory listing, .git exposure, and the standard header set. If the scan can read a config copy from the outside, so can anyone else, and that is the moment you want to know about. Start a free scan and see what the perimeter says.


Related: Directory listing: what an "Index of /" page leaks · An exposed .git directory: why it gives away your whole repository · 13 signs your WordPress site is hacked