Web Development
George Mason University
 
   

HTACCESS

Password Protect a Directory

If your web site address begins with http://www.gmu.edu, HTACCESS allows you to password protect a directory. Follow the instructions below to enable HTACCESS:

  1. Logon to your osf1 account
    Type:
    cd /usr/local/htdocs/your_directory_path

  2. If you have a directory already created for the page(s) that you want to protect, change into that directory:
    cd your_directory_path

  3. If not, type:
    mkdir your_directory_path

  4. Move to the new directory:
    cd your_directory_path

  5. Create a file called ".htaccess" in your_directory_path
    To do this type:
    pico .htaccess

  6. Type the following information just as it appears:
    (directory means your_directory_path)

    AuthUserFile /usr/local/htdocs/your_directory/directory/.htpasswd
    AuthGroupFile /dev/null
    AuthName Your_Site_Name
    AuthType Basic


    <Limit GET>
    require user JohnSmith
    </Limit>

  7. Save the above file, and at your command prompt type:
    /usr/local/apache/bin/htpasswd -c   .htpasswd JohnSmith

    Replace JohnSmith with your first username as it appeared in the previous step-it is case sensitive!!!

  8. Now type each of the below as separate commands:

  9. To add more users, type:

    pico .htaccess

    add another line under require user JohnSmith with a different username i.e. require user JaneSmith

    Example

    < Limit GET >
    require user JohnSmith
    require user JaneSmith
    require user JoeSmith
    < /Limit >

    Save the .htaccess file

  10. At your prompt type:
    /usr/local/apache/bin/htpasswd .htpasswd JaneSmith

    Create a password and remember it! Repeat this step for each new username replacing JaneSmith with the necessary username.

    (**Note the above command is different than what you've typed before. There is no -c; If you use -c it will erase all previous usernames/passwords and create a new file)