LOGO

Secure WordPress Admin: .htaccess Protection Guide

December 5, 2007
Topics:Files
Secure WordPress Admin: .htaccess Protection Guide

Securing Your WordPress Site: Protecting the Administration Folder

For those utilizing WordPress to power their blogs or websites, it’s important to acknowledge the potential for security vulnerabilities. These weaknesses can exist not only within the core software itself, but also within the numerous plugins available. Addressing these concerns, we will explore methods for bolstering security by restricting access to your administration folder.

The Apache web server incorporates a feature enabling password protection for specific folders, functioning independently of your standard WordPress login credentials. This adds an extra layer of defense against unauthorized access.

Essential WordPress Security Considerations

Maintaining a secure WordPress installation requires ongoing attention. While the following list isn't exhaustive, it presents crucial areas to investigate for improved protection.

  • Ensure you are operating the most current versions of both WordPress and all installed plugins.
  • Consider subscribing to security-focused blogs like BlogSecurity.net, which provides updates on vulnerabilities affecting blogging platforms.
  • Verify that your file permissions are configured correctly, adhering to the guidelines provided by WordPress.
  • Employ strong, unique passwords for all user accounts.
  • Regularly back up your complete WordPress installation, including the database.
  • Implement .htaccess rules to lock down your administration folder (detailed below).

Manually Password-Protecting the wp-admin Directory

To begin, create a file named .htaccess within your wp-admin directory. Insert the following code into this file:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/full/web/path/.htpasswd
AuthGroupFile /dev/null
require valid-user

It’s crucial to modify the AuthUserFile line to reflect the complete path to the .htpasswd file, which will be created in the subsequent step. The full path can be determined using the pwd command in a shell environment.

Next, utilize the htpasswd command-line utility to generate the password file. For enhanced security, it is recommended to use a different username and password than those used for your WordPress login.

$ htpasswd -c .htpasswd myusername
New password:
Re-type new password:
Adding password for user myusername

Ensure you are in the directory specified by AuthUserFile and replace "myusername" with a unique identifier for your site. This process will create a file containing data similar to this:

myusername:aJztXHCknKJ3.

Upon accessing your WordPress administration panel, you should now be prompted for a password. The text "Restricted Area" originates from the .htaccess file and can be customized. If you encounter a server error, remove the .htaccess file and restart the process.

As a final security measure, remove write permissions from both files using the chmod command:

chmod 444 .htaccess chmod 444 .htpasswd

Utilizing a .htaccess Password File Generator

Dynamicdrive offers a convenient tool that automates the creation of these files. This is particularly helpful if you lack shell access to your server, allowing you to upload the generated files via FTP or SFTP. http://tools.dynamicdrive.com/password/ Remember to remove write access to the uploaded files after completion.

#WordPress security#.htaccess#WordPress admin protection#website security#hacker protection#WordPress hardening