How to Password Protect a Directory using .htaccess?

How to Password Protect a Directory using .htaccess?

How to Password Protect a Directory using .htaccess?

You may need to password protect a directory in order to limit the sharing of files under it OR may need to protect a private area. You can password protect a directory using a .htaccess file which has to be placed under a directory which needs to be protected.

Create a .htaccess file

vi /home/username/.htaccess

Once created, add the following lines to it:

AuthUserFile /home/username/.htpasswd
AuthName “Private Area”
AuthType Basic
require valid-user

where, ‘username’ is the actual username of your domain. Now, create a .htpasswd file under the /home/username/ directory.

vi /home/username/.htpasswd

In order to grant access to the directory for specific users, you need to place all the users along with their passwords in the below format:

username1:encryptedpassword
username2:encryptedpassword

There is no limit in adding users to this file, just make sure each user should be on a separate line and you can encrypt passwords using any available tool on the internet.

Share this post

Comment (1)

  • sextet Reply

    Thanks for s᧐me other informative website. The plɑce else could I
    am getting that type of info written in such an ideal
    way? I havе a mission that I am simply now operating on, and Ӏ have been on the
    look out for sսch info.

    July 1, 2022 at 2:37 pm

Leave a Reply

Your email address will not be published.