How to make a folder password protected

This is a very simple task to do but still sometimes you need a guide for smooth sailing. Instead of mailing the same content again and again I decided to delegate the work to blog. I am covering the htaccess method for password protection.

Make sure you have access to use htaccess (Check your apache config or ask your hosting company). In order to protect a folder, you need to have two files inside the folder,

  • .htaccess:
    AuthType Basic
    AuthName "By Invitation Only"
    AuthUserFile (Path to the passwd file)
    Require user (username)

    Example
    AuthType Basic
    AuthName "By Invitation Only"
    AuthUserFile /home/www/secret/passwd
    Require user ajinimc

  • passwd: Go to http://spectrum.troy.edu/password/ and type the username and choose a password, lets take an example (username: ajinimc, password: 1234). The website created the encrypted password ajinimc:C6DneUKC5gSG2. Now add this to passwd file.

Now the folder is password protected. Try http://www.idealwebtools.com/secret/ . Hope it helps.

2 Replies to “How to make a folder password protected”

  1. I will refer to my colleagues as well, they do ask me this again and again. Apache not allowing htaccess, here is how I handled it then.

    I had to edit conf.d/xxxx.conf in order to get /monitoring/ to link.

    eg.,

    Alias /monitoring/ /var/www/www.xxxx.dyndns.org/web/monitoring/
    #ScriptAlias /monitoring/ /var/www/www.xxxx.dyndns.org/web/monitoring/

    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    Then it worked fine, unless I have missed something???

  2. Thanks Matt and Aji for the help. I have tried it and it works well. So it goes to my list of documents.

Comments are closed.