Limit access to your WordPress login page by using .htpasswd file

No matter how big your website is, you should take extra care of security. There are many different ways of protecting your WordPress website. In this article, we will show you how to limit access to your login page and stop people from even trying to login.

If you have a standard installation of WordPress, you will have the same link to the login page as millions of other users. That means it is easy to access your login page just by typing /wp-admin at the end of your homepage. Yeah, it is password protected but still opened for various brute force attacks. It would be a good idea to prevent unauthorized access to this page.

If your site is hosted on a PHP hosting (which it probably is), you can use a simple method by adding a username and password for you login page.

It can be done by editing .htaccess and creating a .htpassword file.

Let’s start by creating a password file and uploading it to your server:

  1. Go to http://aspirine.org/htpasswd_en.html
  2. In the left box, add one user per line
  3. Click “Generate Passwords”
  4. In the right box, click “Generate htpasswd content”
  5. Save the content from the second box into “.htpassswd” file without any extension
  6. Even though you can name this file whatever you want (like password.txt), it is recommended to use default file name. Apache server is configured in a way it won’t let access to this file while other file names/extensions would be available for editing thus making all this extra security worthless.

  7. Upload newly created file on your server

Now you’re ready to edit .htaccess file which can be found on your server in the main directory:

  1. Navigate to .htaccess and open it
  2. add the following lines to your file:
  3. # Stop Apache from serving .ht* files
    <Files ~ "^\.ht"> Order allow,deny Deny from all </Files>
    # Protect wp-login
    <Files wp-login.php>
    AuthUserFile ~/.htpasswd
    AuthName “Private access”
    AuthType Basic
    require user wploopuser
    </Files>
  4. Change ~/.htpasswd to location of the file you have uploaded in the previous step
  5. Change “wploopuser” to username you have entered into password generator and the file
  6. Save changes

Now, before you can even get to the WordPress login page you will have to enter username and password you have created in the previous steps. Yes, now you have to enter two different usernames and passwords before you can login to your site; don’t be lazy, this might save you from random attacks and save you a site.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *