Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

WordPress Security Keys & Salts: How to Generate and Change Them

· 5 min read · Home Security

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

WordPress security keys and salts are authentication tokens that encrypt login sessions and cookies, making it much harder for attackers to hijack your admin account or forge login data. This guide explains what they do, how to generate new ones, and how to safely update them in your wp-config.php file — a simple task that takes about five minutes and can be done from any hosting control panel or FTP client.

What You'll Need

  • Access to your WordPress site's files, either via FTP/SFTP or your hosting file manager (cPanel, Plesk, etc.)
  • A text editor (Notepad, Sublime Text, VS Code — anything that saves plain text)
  • Your WordPress admin login credentials (you'll be logged out after changing keys)
  • Optional: a backup of your wp-config.php file (recommended)

Step-by-Step

  1. Back up your current wp-config.php file. Navigate to your WordPress root directory (where you see folders like wp-admin, wp-content, and wp-includes). Download wp-config.php to your computer or copy its contents to a text file. This ensures you can restore the old configuration if anything goes wrong.
  2. Generate new keys and salts. Go to the official WordPress salt generator at https://api.wordpress.org/secret-key/1.1/salt/ (or use the alternate page at https://api.wordpress.org/secret-key/1.1/salt/). This page displays eight lines of code, each defining a constant like AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT, and NONCE_SALT. Copy all eight lines exactly as shown.
  3. Open wp-config.php for editing. Using your text editor, open the wp-config.php file you downloaded or locate it in the file manager. The file contains PHP code and looks like a long text file with lines starting with define(.
  4. Find the existing salt definitions. In the file, search for AUTH_KEY or SALT. You'll see a block of eight lines starting with define('AUTH_KEY', and ending with define('NONCE_SALT',. These are the current keys.
  5. Replace the old keys with the new ones. Delete the entire block of eight lines and paste the new lines you copied from the generator in their place. Make sure you replace all eight lines — missing even one can cause issues. Do not change any other lines in the file.
  6. Save the file and upload it back. If you downloaded the file, save it with the same name (wp-config.php) and upload it to the same location, overwriting the old one. If you're using a file manager, simply save the changes.
  7. Log out and log back in. After the file is updated, you'll be automatically logged out of your WordPress admin. Go to your login page (e.g., yourdomain.com/wp-login.php) and log in with your username and password. That's it — your keys are now changed.

Common Mistakes

  • Editing the wrong file. Make sure you're editing wp-config.php in the root directory, not a backup or a file inside wp-content.
  • Changing only some keys. All eight constants must be replaced. Leaving old ones mixed with new ones can cause login issues or errors.
  • Adding extra spaces or characters. The lines must be exactly as generated — no extra spaces, line breaks, or characters. A stray space can cause a PHP parse error.
  • Forgetting to save the file in plain text. Some editors save as UTF-8 with BOM, which can cause issues. Use plain text encoding (UTF-8 without BOM is fine).
  • Not backing up first. If you make a mistake, you can't easily revert without a backup.

Tips

  • Change keys periodically. It's good practice to rotate keys every few months, especially after a security incident or if you suspect your site has been compromised.
  • Use the official generator. Only use the WordPress.org salt generator. Do not use random strings from other sites, as they might be logged or insecure.
  • Keep keys secret. Never share your keys publicly or in support forums. They are as sensitive as your password.
  • Consider using a security plugin. Some plugins (like Wordfence or iThemes Security) offer one-click key rotation, but the manual method is just as effective.
  • Test after changing. After logging in, check that your site loads correctly and that you can access the admin dashboard. If you use caching, clear the cache.

Troubleshooting

  • You get a "syntax error" or white screen after saving. This usually means a mistake in the file. Restore your backup, then try again carefully. Check for extra spaces, missing semicolons, or broken lines.
  • You can't log in after changing keys. This is normal — you're logged out. If you try to log in and it fails, wait a few minutes and try again. If it still fails, your keys might be malformed. Restore the backup and redo the process.
  • The site shows "Error establishing a database connection." This is unlikely but could happen if you accidentally altered the database settings in wp-config.php. Restore your backup immediately.
  • Keys don't seem to take effect. Clear your browser cookies and cache, then log in again. Also, if you use a caching plugin, purge the cache.
  • You can't find wp-config.php. It's in the root directory. If you don't see it, your hosting may hide it. Use FTP and enable "show hidden files" or check your file manager settings.

Frequently Asked Questions

Do I need to change security keys and salts?

Not routinely, but it's a good security practice. Changing them invalidates all existing login sessions and cookies, which can help if you suspect unauthorized access.

What happens after I change the keys?

All users (including you) are logged out. They'll need to log in again. Existing cookies become invalid, so any session hijacking attempts are thwarted.

Can I use any random string as a key?

Technically yes, but the official generator creates highly random strings that are more secure. If you make your own, use a strong random generator and make sure the strings are long and unpredictable.

Will changing keys break my site?

No, if done correctly. The only immediate effect is that users are logged out. In rare cases, if you have a caching plugin or CDN, you may need to clear those caches.

How often should I change them?

There's no hard rule, but every 3-6 months is reasonable. Also change them immediately if you suspect a breach or after removing a malicious plugin.

Can I change keys from the WordPress admin dashboard?

Not directly. You need to edit wp-config.php. Some security plugins offer this feature, but the manual method is universal.