WordPress Security
WordPress is a safe system by itself, and most hacked sites are hacked because of old plugins, weak passwords or bad hosting. With a few good habits you can stop the most of the attacks.
Security checklist
- Keep everything updated: WordPress, themes and plugins. Most attacks use known problems of old versions.
- Remove what you do not use: delete (not only deactivate) unused plugins and themes.
- Use strong and different passwords, and a password manager. Turn on two factor login for admins.
- Give the lowest role a person needs. See Users and Roles.
- Install only trusted plugins and themes: from WordPress.org or known sellers, never nulled copies.
- Use HTTPS on the full site.
- Take regular backups and test them. See Backup and Update.
- Limit login attempts and keep an eye on the failed logins with a security plugin.
Check that the core files are not changed
WP-CLI compares your core files with the official checksums from WordPress.org. If a file is changed or added, it tells you:
$ wp core verify-checksums
Success: WordPress installation verifies against checksums.
Do the same for plugins from WordPress.org:
$ wp plugin verify-checksums akismet
Success: Verified 1 of 1 plugins.
Make the file editor off
The dashboard has a theme and plugin editor. If a hacker gets an admin login, he can put code with it. Remove the editor with one line in wp-config.php:
define( 'DISALLOW_FILE_EDIT', true );
Protect wp-config.php and uploads
# in .htaccess (Apache): block direct access to wp-config.php
<Files wp-config.php>
Require all denied
</Files>
File permissions on most servers: folders 755, files 644, and wp-config.php 600 or 640. Never use 777.
What to do if the site is hacked
- Put the site in maintenance mode, or ask your host for help.
- Change all passwords: WordPress users, database, hosting and FTP. Create new salts.
- Reinstall the WordPress core and all plugins and themes from fresh copies. Check with
wp core verify-checksums. - Look for unknown admin users and unknown files in
wp-content/uploads(PHP files should not be there). - Restore a clean backup if you have one, and then update everything.
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |