The wp-config.php file stores WordPress security keys and so-called salts. They are used to create signatures for cookies, nonces, and other mechanisms related to user authentication. If an attacker obtains these values along with a stolen cookie, access to an account may remain possible even after the password is changed.
Rotating the keys invalidates old WordPress sessions and forces all users to sign in again. This is a useful procedure after a suspected breach, a leaked backup, or accidental exposure of wp-config.php, but it does not replace a full incident investigation.
What WordPress Security Keys and Salts Are
In a typical configuration, WordPress uses eight related values: AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, as well as AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT, and NONCE_SALT. They are not administrator passwords, but they affect how WordPress creates and verifies authentication tokens.
These values are usually stored in wp-config.php. This is why the file must be protected as carefully as backups, environment variables, and access to the hosting control panel. If the keys become known to third parties, old cookies may remain valid until the corresponding sessions are revoked by another method.
Rotation consists of replacing all keys and salts with new, randomly generated values. Afterward, signatures on old cookies no longer match the new configuration, so WordPress asks users to sign in again.
- Do not publish keys in reports, tickets, chats, or repositories.
- Do not use the same values on different sites.
- Do not replace the keys with short phrases, company names, or values that are easy to guess.
When Key Rotation Is Really Necessary
The most obvious reason is a suspected compromise of the site or its credentials. If an attacker may have read wp-config.php, accessed a backup, or exploited a server vulnerability, changing the keys should be considered one of the first steps after the incident has been contained.
Rotation is also appropriate after a migration if the configuration file was transferred over an insecure channel, stored in a public repository, or accessible to former contractors. It can also be performed after restoring the site from a backup if it is unknown who had access to the archive.
At the same time, changing the salts should not be treated as proof that the site has been cleaned. If backdoors, malicious plugins, modified files, or newly created accounts remain in the system, an attacker may regain access.
- After rotation, check administrator accounts, cron jobs, plugins, themes, and server logs.
- If the incident is ongoing, restrict access and preserve log copies first, then change the configuration.
- After changing the keys, update administrator, SSH, FTP, database, and hosting-panel passwords if they may have been exposed.
Preparing to Change the Keys
Before starting, create a backup of wp-config.php and store it in a secure location. Do not leave the copy in the site's public directory under an obvious name such as wp-config-backup.php: the web server or an incorrect configuration could expose its contents. It is better to store the file outside the web root or in a storage location with restricted access.
If the site is important to the business, test the procedure on a staging copy first. Make sure you have access to the administrator account, SSH, or the hosting control panel, and understand how to restore the previous configuration if something goes wrong.
Notify the team about the planned operation. After rotation, all active users, including administrators, will be logged out. This is normal behavior, so do not schedule the procedure while editors are publishing content or technical work is taking place.
- Check that wp-config.php is writable by the user or process that runs WP-CLI.
- Record the current state of the site: log errors, the list of administrators, and important active integrations.
- Make sure the database and file backups are suitable for restoration, rather than merely having been created.
- For a production site, prepare a maintenance window and a way to quickly restore the previous file.
How to Rotate Keys with WP-CLI
If WP-CLI is installed on the server, the simplest method is to run the command from the WordPress root directory. It generates new values and updates the key block in wp-config.php.
Run the command as a user who has access to the site files. If WordPress is not installed in the current directory, specify the correct path or change to it before running the command.
- After running the command, check that it completed without errors and that the file actually changed.
- Do not paste old or new keys into public terminal logs, ticketing systems, or public logs.
- If wp-config.php belongs to another user, adjust permissions carefully: excessive permissions can create a new vulnerability.
cd /path/to/wordpress
wp config shuffle-salts
Manually Replacing Keys in wp-config.php
If WP-CLI is unavailable, the keys can be replaced manually. In wp-config.php, find the definitions block that begins with AUTH_KEY and contains four keys and four salts. Replace the values to the right of the equals sign with new, long, random strings without changing the constant names or PHP syntax.
The new values must be independent of one another. Do not copy one string into all constants or use the administrator password. For generation, use a strong cryptographic generator available in your environment or a trusted WordPress key generator.
After editing, check that every line has correct quotation marks and a semicolon. An error in wp-config.php can cause a syntax error or make the site unavailable.
- Do not change DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, $table_prefix, or other parameters unless there is a separate reason to do so.
- Do not add spaces, HTML, or comments inside the key values.
- Save the file with the correct encoding and restore secure access permissions after editing.
- If the configuration is generated from environment variables or a secrets store, change the values there rather than only in the generated file.
define( 'AUTH_KEY', 'нове-випадкове-значення' );
define( 'SECURE_AUTH_KEY', 'нове-випадкове-значення' );
define( 'LOGGED_IN_KEY', 'нове-випадкове-значення' );
define( 'NONCE_KEY', 'нове-випадкове-значення' );
define( 'AUTH_SALT', 'нове-випадкове-значення' );
define( 'SECURE_AUTH_SALT', 'нове-випадкове-значення' );
define( 'LOGGED_IN_SALT', 'нове-випадкове-значення' );
define( 'NONCE_SALT', 'нове-випадкове-значення' );
What to Check After Rotation
Open the site in a private browser window and test access to the administration area. Then test logging out and signing in again, forms, media uploads, caching, and key store or user-account scenarios.
All administrators must sign in again. If a particular cookie or session continues to work, check whether all eight values were actually changed and whether the request is being handled by the WordPress installation you edited.
For sites using Elementor, separately test the editor, template saving, and forms after signing in again. Salt rotation should not change Elementor content or settings, but configuration, caching, or file-permission errors may appear at the same time.
After testing, review PHP, web-server, and security-system logs. Look for unknown logins, account creation, requests to suspicious PHP files, and authentication errors.
- Delete or revoke old backups if they contain compromised keys and are no longer needed.
- Clear the cache at the WordPress, reverse-proxy, or CDN level only when necessary; this does not replace cookie rotation.
- Check that HTTPS works correctly, especially if the site uses secure cookies.
- Make sure the system contains no unknown administrators or suspicious scheduled tasks.
Common Mistakes and Limitations
The most common mistake is changing only one or two lines. To fully revoke standard WordPress sessions, the entire set of keys and salts must be updated. Another problem is editing the wrong wp-config.php: a server may contain staging, development, and production copies.
Do not try to solve a stolen password, malicious code, or vulnerable plugin through rotation. If an attacker has filesystem access, they can change the configuration again or create a new session.
Do not delete wp-config.php or generate a new configuration without understanding its parameters. This can break the database connection or erase important settings.
- Rotation does not remove backdoors, web shells, malicious mu-plugins, or modified theme files.
- Rotation does not automatically revoke third-party service tokens, API keys, SSH keys, or hosting passwords.
- If the site runs in a cluster, make sure all nodes use the same current configuration.
- After an incident, update WordPress, the theme, and plugins, and remove unnecessary components.
Frequently asked questions
Will key rotation log out all users?
Yes. Old cookies and active WordPress sessions will fail verification, so administrators and regular users must sign in again. This is expected behavior.
Do the keys need to be changed after every WordPress update?
No. A routine WordPress update does not by itself require rotation. Perform it after a suspected compromise, configuration leak, insecure migration, or as part of incident response.
Will rotation remove malicious code from the site?
No. It only invalidates old standard WordPress sessions. Separate checks of files, the database, users, cron jobs, logs, and server access are required.
What should I do if the site stops working after rotation?
Check the syntax of wp-config.php, the file permissions, the environment configuration, and the PHP logs. If the problem was caused by an editing error, use the prepared backup and then repeat the operation carefully.
Conclusion
Rotating WordPress security keys is a quick way to forcibly terminate standard sessions after a possible cookie or wp-config.php leak. The safest approach is to perform it through WP-CLI after creating a backup and verifying access.
After changing the salts, continue the investigation: update passwords and secrets, and check files, users, plugins, logs, and the server. Only comprehensive incident response—not rotation alone—helps restore control of the site.