Westhost Logo

Knowledgebase

Search Articles

Categories

  • Back to Security

    Can I Use .htaccess To Password Protect A Directory


    Here are some instructions on how to use the .htaccess method for protecting files and directories. It can be pretty simple to do.

    The system requires two files -- the .htaccess file and .htpasswd file.

    The .htaccess Code


    AuthType Basic
    AuthName "restricted area"
    AuthUserFile /var/www/html/protect-me-dir/.htpasswd
    require valid-user


    The above code protects a directory called "protect-me-dir" inside of the html directory. Be sure to use the correct folder path for your account type.

    The .htpasswd Code


    admin:daWHfZrDLB88
    bob:roFulYxC2.8ws
    developer:csmnmq.M8T5ho


    The .htpasswd file contains the usernames and passwords of allowed users. This example shows 3 different users. One per line. The passwords are MD5 encrypted for security purposes.

    To generate encrypted passwords for your .htpasswd file, you can use this password generator. http://www.htpasswdgenerator.net/


    Related Articles

    Does WestHost Allow Sudo
    How To Connect With Putty Via SSH
    How To Perform A Trace Route
    My Account Has Been Hacked What Do I Do
    What Is SSL

    Can’t Find what you need?

    No worries, Our experts are here to help.