Rotating the eight *_KEY and *_SALT constants in wp-config.php is the fastest forced logout WordPress gives you. The instant that file is saved, every authentication cookie, every nonce sitting on a form somebody already has open, and every outstanding password-reset link stops verifying — for the intruder and for you. That is the point during an incident, and it is also the bill: you get signed out of wp-admin mid-response, editors lose half-finished screens, and a shopper’s logged-in cart can empty under them. This guide gives the safe order of operations on a cPanel account, the file-ownership trap that takes the site down right after an otherwise clean rotation, how to prove the old cookies are dead, and what salt rotation does not fix.
What you’ll accomplish
- Every active session on the site invalidated in one save, including any the intruder is holding.
- A rotation done in the right order, so a stolen password cannot simply rebuild the session you just killed.
wp-config.phpleft syntactically valid and owned by the account user rather than by root.- Caches flushed, so the change is visible instead of hidden behind a stale logged-in page.
- Evidence — with commands — that an old cookie is rejected, a fresh login works, and the public site is still up.
Prerequisites
WordPress 6.x on a cPanel account, plus SSH or cPanel’s Terminal. Every command below runs as the account user (cpuser throughout — substitute yours) from the WordPress directory. Nothing here needs root, and running it as root is the most common way to break the site immediately afterwards.
WP-CLI turns this into a single command. cPanel servers usually ship it as wp; confirm with wp --info. If it is absent, the fallback is the WordPress.org secret-key endpoint plus an editor, covered in step 5.
A fresh copy of wp-config.php, taken in step 3 rather than trusted from last night’s backup, and a working restore path for the account as a whole.
A maintenance window, or a decision that you are taking one anyway. Every logged-in user is ejected the moment you save. On a membership site or a store, tell whoever owns customer communication first.
How it works
The four *_KEY and four *_SALT constants are inputs to the HMAC that WordPress computes over a cookie’s username, expiry and session token. wp_generate_auth_cookie() hashes those pieces with a key derived from AUTH_KEY and AUTH_SALT (or the SECURE_AUTH_* pair over HTTPS), and wp_validate_auth_cookie() recomputes the same hash on the way back in. The LOGGED_IN_* pair signs the weaker wordpress_logged_in_ cookie that only proves identity, and NONCE_KEY / NONCE_SALT feed wp_create_nonce() and therefore every admin-bar action, every REST call from the block editor, and the token embedded in a password-reset link. The wp-config.php reference documents each constant.
Because they are PHP constants and not database rows, rotation needs no migration and no downtime for the write itself. Change the file, and the next request recomputes with new inputs. What that request cannot do is verify a hash produced with the old ones, so it treats the cookie as absent and hands the visitor the login form.
The line between what dies and what survives is worth memorising. Password hashes live in wp_users.user_pass and are untouched — a leaked password still works after rotation. Application passwords are hashed in usermeta and also survive, so revoke a leaked integration explicitly. The token list in the session_tokens usermeta key survives too: rotation does not delete those rows, it only makes the cookies that reference them unverifiable. Posts, media and orders are entirely unaffected.
The failure mode nobody plans for is caching. A full-page cache holding a rendered logged-in view keeps serving it, so a tester reloads, sees their name in the admin bar, and concludes the rotation failed. WooCommerce is the sharpest case: the cart is keyed to the customer session, and rotating mid-checkout drops a signed-in shopper back to an anonymous cart. On a busy store that is a real cost to weigh, not a footnote.
Multisite deserves a flag before you start. The constants live in the single network-wide wp-config.php, so a rotation logs out every site on the network at once, including the ones nobody reported a problem with.
Step-by-step
-
Contain first, then work the order. Rotating salts while the intruder still has a working password or an active shell just restarts the clock — they log back in with the same credential. Block the source, take the site into maintenance mode if the abuse is live, then move down the list.
-
Reset the passwords that matter before you rotate. Salts never touch password hashes, so this step has to come first or the forced logout accomplishes nothing.
wp user list --role=administrator --field=ID wp user reset-password $(wp user list --role=administrator --field=ID | tr '\n' ' ')The first command prints one numeric ID per line. The second prints a
Success: Updated password for user ...line per account and mails each one a new password. If mail is unreliable on the account, reset your own withwp user update <id> --user_pass=<value>and deal with the rest by hand. -
Copy
wp-config.phpbefore you touch it, preserving ownership.cd /home/cpuser/public_html cp -a wp-config.php /home/cpuser/wp-config.php.$(date +%F-%H%M).bak ls -l /home/cpuser/wp-config.php.*.bakcp -akeeps mode, owner and timestamps. The listing should showcpuser cpuseras owner and group. Keep the copy outsidepublic_html— a.bakbeside the original is readable over HTTP on plenty of configurations, and it contains your database credentials. -
Confirm the eight constants are all present, without printing their values.
wp config list --fields=key,type | grep -E '_KEY|_SALT'You want eight rows, each of type
constant:AUTH_KEY,SECURE_AUTH_KEY,LOGGED_IN_KEY,NONCE_KEY,AUTH_SALT,SECURE_AUTH_SALT,LOGGED_IN_SALT,NONCE_SALT. Fewer than eight means the install predates a constant or somebody trimmed the block; add the missing ones in the next step rather than leaving WordPress to fall back on a weaker default. -
Rotate with WP-CLI.
wp config shuffle-saltsIt rewrites the values in place and prints a
Success:line naming the keys it shuffled. Editing in place is why this is the preferred route: the file’s inode, owner and mode are unchanged, which is exactly the property a hand-edit tends to lose. Add--forceif step 4 showed a missing constant and you want it created rather than skipped.If
wpis unavailable, fetch a fresh block from the official endpoint instead:curl -s https://api.wordpress.org/secret-key/1.1/salt/ > /home/cpuser/salts.txt grep -c '^define' /home/cpuser/salts.txtThe count must be
8. Openwp-config.phpin an editor, delete all eight existingdefine()lines for these constants, paste the new block in their place, and save. Replace the whole block — a half-rotation leaves some cookie paths validating and others not, which is far harder to reason about than either extreme. Then deletesalts.txt. -
Prove the file still parses before anything else.
php -l wp-config.php grep -c "define( *'AUTH_KEY'" wp-config.phpThe first must print
No syntax errors detected in wp-config.php. The second must print1; a2means you pasted the new block without removing the old one, and PHP will emit a constant-already-defined notice on every request. -
Put ownership and mode back where cPanel needs them. This is the step that takes sites down. Under suEXEC and PHP-FPM the account’s PHP process runs as
cpuser, and awp-config.phpleft owned byroot— which happens whenever you edit as root, or write a new file and move it over the old one — produces a blank page or a 500 on the very next request.stat -c '%U:%G %a %n' wp-config.php chown cpuser:cpuser wp-config.php chmod 640 wp-config.phpExpect
cpuser:cpuser 640 wp-config.phpfrom the check. If it already reads that way, skip the two commands. Thechownneeds root; if you are not root, restore from the step 3 copy and redo the edit as the account user. The wider account baseline is in file permissions and ownership on cPanel. -
Flush every cache layer, in order from closest to the database outward.
wp cache flush wp transient delete --allwp cache flushprintsSuccess: The cache was flushed.— on a site with no persistent object cache it is a no-op and still safe. Then purge the full-page cache in front of PHP. With LiteSpeed Cache installed,wp litespeed-purge alldoes it; otherwise use the plugin’s own admin control, and purge the CDN afterwards if one is in the path. -
Clear the stale session rows, optionally. Rotation leaves the token list behind in
usermeta; clearing it keeps the audit picture clean.for id in $(wp user list --role=administrator --field=ID); do wp user session destroy "$id" --all; doneEach iteration prints a
Success: Destroyed all sessionsline. This is tidy-up, not the control — the salts already did that work.
Validate it works
Prove the public site is fine first, because that is the failure that costs you money while you are testing logins:
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/
200 is the answer you need. A 500 sends you straight back to steps 6 and 7.
Now prove an old session is dead. Take a wordpress_logged_in_* cookie value you captured before the rotation and present it to an admin page:
curl -s -o /dev/null -w '%{http_code}\n' -b 'wordpress_logged_in_0123abcd=oldvalue' https://example.com/wp-admin/
Expect 302. WordPress cannot verify the hash, treats the request as anonymous, and redirects to wp-login.php. A 200 here means something in front of PHP answered from cache — go back to step 8.
Then log in through a browser and confirm the new session survives a reload, and that nonce-signed traffic works again:
wp eval 'echo wp_create_nonce( "wp_rest" ), "\n";'
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/wp-json/wp/v2/types
The first prints a fresh ten-character nonce, which confirms NONCE_KEY and NONCE_SALT are readable and consistent. The second must return 200. In the browser, open the block editor and save a draft — that exercises a cookie-authenticated REST write end to end, which is the check that actually matters.
Finally, record the date and the reason in the incident log. If you do not yet keep one, what to log in WordPress covers the events worth capturing.
Troubleshooting
White screen or HTTP 500 straight after saving. Almost always a stray character, a smart quote pasted from a browser, or a duplicated define(). Read the account’s PHP error log rather than guessing:
tail -30 /home/cpuser/public_html/error_log
A PHP Parse error: syntax error, unexpected ... names the line. Restore the step 3 copy, redo the edit, and re-run php -l before reloading.
wp-config.php ends up owned by root. Under suEXEC or CageFS the account’s PHP process cannot read a root-owned config, and you get a blank page with a permission entry in the log. Fix it with the chown/chmod pair in step 7. This is why wp config shuffle-salts run as the account user beats any workflow that writes a new file and moves it into place.
Users report they are still logged in. Two causes, easy to tell apart. If a curl request with no cookies returns a page showing an admin bar, a full-page cache is serving a stored logged-in view — purge it. If a real browser session survives, a plugin is keeping its own sessions outside the WordPress cookie system; some membership and SSO plugins do exactly that and need their own flush.
REST or AJAX calls fail with 403 rest_cookie_invalid_nonce. Expected for the first minutes. A tab open since before the rotation is holding nonces built from the old NONCE_KEY. A hard reload issues new ones. If it persists past a reload on a fresh login, the page is being served from cache with a baked-in nonce — that is a caching bug the rotation only made visible.
Multisite: the whole network logged out. The constants are shared network-wide, so rotation on one site rotates them for all of them. Check before you start:
wp config get MULTISITE --type=constant
A 1 means plan the announcement for every site owner, not just the one that reported the incident.
When this is the wrong approach
Salt rotation is a forced logout. It is not a cleanup, and treating it as one is how sites get reinfected the same week.
It does not remove a web shell dropped in wp-content/uploads/. It does not remove a malicious administrator account the attacker created — that account simply logs in again with its own password. It does not revert a modified core or plugin file, an injected must-use plugin, a rogue cron event, or a database-level redirect in wp_options. It does not close whatever vulnerability let them in, so an unpatched plugin stays exploitable the moment the rotation finishes.
A genuine compromise needs the rest of the work: wp core verify-checksums and wp plugin verify-checksums --all to find modified files, an audit of wp user list --role=administrator, a read of wp_options for injected values, an inspection of wp-content/mu-plugins/, a review of cron entries, a patch pass on everything out of date, and — if any of that turns up something you cannot account for — a rebuild from a backup taken before the first sign of intrusion. Salt rotation belongs in that sequence, right after the passwords change. It replaces none of it.
Rotating on a routine schedule when nothing has happened is mostly ceremony. Salts do not expire, and the constants are only exposed if wp-config.php itself is exposed — in which case you have a far larger problem. Rotate on a trigger: a credential leak, a departing administrator, a shared password, a restored backup of unknown provenance, or an install still carrying the WordPress placeholder values. WP-CLI’s config command reference covers the rest of the file’s handling.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.