How to Password Protect a Directory

A password-protected directory protects that directory and all directories below it. To password-protect a directory(ies) in your AFS Website, log in to - and run the command:


Alternatively, you can use the procedure below to password-protect the entire contents of a directory in your public_html directory (The directory in the example below is titled "DIR").

cd DIR

  1. htpasswd -c .htpasswd <username>
    (e.g., htpasswd -c .htpasswd cis101)
    (htpasswd requests a password for cis101)
  2. Use a text editor to create the file ".htaccess" (without the quotes), with the following lines:
AuthName <GroupName>
AuthType Basic
AuthUserFile <path-to-.htpasswd>
AuthGroupFile /dev/null
<Limit GET>
require valid-user


  • <GroupName> can be any name¬†(e.g., CIS101); it is not the same as username.
  • Groupname is displayed when the Password box pops up, and is used only as a name for the directory being protected.
  • If <GroupName> is more than one word, enclose it in double quotes ( " )
  • <path-to-.htpasswd> is the full path to the location of the ".htpasswd" file for this directory. If DIR is ~abc1234/public_html, then <path-to-.htpasswd> is:


Last Updated: June 29, 2017