How to Password Protect an HTML Directory

1. Open a terminal window and change to the public_html directory. Make a new directory, say Test, with the command

mkdir Test <RETURN>

2. Set the permissions:

chmod 755 Test <RETURN>

3. Inside the Test directory, use a text editor to create a hidden file called .htaccess. The contents of the file are as follows: (the /u/fac/rahe needs to be modified to your path)

AuthUserFile /u/fac/rahe/.htpasswd

AuthGroupFile /dev/null

AuthName ByPassword

AuthType Basic

<Limit GET>

require user maury

</Limit>

This allows user maury to access the directory, if he has the password.

4. In a terminal window, set the permissions for the new file by

chmod 744 .htaccess <RETURN>

5. In your home directory (not the public_html), create a hidden file of users and passwords called .htpasswd by executing the command

htpasswd -c .htpasswd maury <RETURN>

(The -c is only used the first time, to create the file.) It will then ask for the password and a retype of the invisible password. The new user then has access to the the directory.

Try it: the user is sue and the password is sue Password Protected Directory