This tutorial was created by Hurricane Electric. We have permission to re-publish this information.
The Restricted Access Document
The document "Restricted Information" is only available to user john with password orange and user sheri with password apple. The first time you click on "Restricted Information", your web browser should prompt you for a user name and password. If it does not you may be using a web browser which is not HTTP authentication capable.
Ingredients
NOTE: Please make sure you are setting this up in the directory that you want password protected. The .htpasswd file will end up in the wrong directory otherwise. For more information on how to use Unix, please check out this great Unix Tutorial.NOTE: There is no correspondence between the usernames and passwords used for accounts on this server and usernames and passwords in any specific .htpasswd file. A user doesn't need to have an account on this system in order to be validated for access to files protected by HTTP-based authentication.
- The web document to be protected. Actually, access is restricted by directory so all files in the same directory will be protected.
- The file .htaccess.
This file should be in the directory which contains the documents to restrict access to. The contents of this file specify the name of the password file.For example if you were user jdoe with web documents in the local directory "/home/jdoe/public_html/goodstuff" that you wanted to restrict access to, your .htaccess might look like:
AuthUserFile /home/jdoe/public_html/goodstuff/.htpasswd
AuthName jdoe_goodstuff
AuthType Basic
<Limit GET>
require valid-user
</Limit>Note that .htaccess will not work if there are extra spaces after AuthUserFile.
- The file .htpasswd.
This file contains the passwords of the users.
To create the .htpasswd file log in to this server using telnet, change directory to the directory you want to restrict access to, and type:
htpasswd -c .htpasswd someuser
for the first user (where someuser is the username). You will then be prompted twice for the user's password. The -c option causes the .htpasswd file to be created. For each additional user type:
htpasswd .htpasswd someuser
Main Page
Web Hosting Info
WebMaster Resources
Contact