Levich webpage http://www-levich.engr.ccny.cuny.edu is on a new server   : Levich mail server migrated.
Resources and Services
Help
System Administration
Quick Links

How to password protect a directory for your website?

Dr. Junjun Mao

Research Associate, Levich Institute at City College of New York, Last update: 09/01/2006


1. Setup the directory you want to protect.

Suppose you want to password protect directory "private_data". This directory must be somewhere under your public_html, otherwise it won't be visible to the web browsers. Create a file ".htaccess" in this directory and put these lines in:

AuthUserFile /home/jmao/.htpasswd
AuthName "My files"
AuthType Basic
require valid-user

The first line indicates the location of file .htpasswd. File .htpasswd contains user name and password that authenticate the allowed users that can view files in the folder with .htaccess, private_data in this example. This file should be out of the scope of public_html, so that it is not visible through web browsers.

The second line is the message in the pop-up window that prompts you to type in password. Keep the 3rd and 4th lines unchanged.

2. Setup the password file

Now goto the directory you want to put file .htpasswd, run

htpasswd -c .htpasswd username

to create a new .htpasswd file, or update a user password without -c.


jmao@ccny.cuny.edu