Home FAQ's Section 3 How can I password protect files on my web site?
How can I password protect files on my web site? PDF Print E-mail

You can password protect your web pages via the htaccess facility and the htpasswd program, which are currently available on our Linux systems (linux.engr.ucsb.edu). You will need to dedicate a subdirectory for your password-protected files.

Information on htaccess can be found here:

http://www.he.net/info/htaccess/demo.html

Information on how to use htpasswd can be found here:

http://httpd.apache.org/docs/programs/htpasswd.html

Our Apache web server is configured to look for a file named .htaccess.

A SAMPLE setup could be done like this:

Make the directory containing the password protected files your current directory. Create a file named “.htaccess” there.

.htaccess file SAMPLE contents:

AuthUserFile /fs/home1/student/public_html/.htpasswd

AuthName "Name of your Web Pages"

AuthType Basic

require valid-user

(Note that .htaccess will not work if there are extra spaces after AuthUserFile.)

Then for the first user, from a command prompt on a linux system, type:

# /usr/bin/htpasswd -c .htpasswd joe_user

You will then be prompted twice for the user's password. The -c option causes the .htpasswd file to be created.

Set files in this directory for world read (chmod 644).

For each additional user type:

htpasswd .htpasswd some_user

When users supply user name and the password that you provided to the htpasswd program, they get access to the directory and its contents.

 
Copyright © 2008 The Regents of the University of California, All Rights Reserved.