• Here is a quick and easy HOWTO for setting up .htaccess password protection on web-accessable directories. It’s really easy, but it’s always nice to have the syntax right at your fingertips.

    First, find your way into the directory you want to protect.

    % cd /path/to/secure/directory

    Next, create a file in this directory called “.htaccess” and insert the following lines:


    AuthUserFile /path/to/secure/directory/.htpasswd
    AuthGroupFile /dev/null
    AuthName "Secure Document"
    AuthType Basic

    <LIMIT GET PUT POST>
    require user username
    </LIMIT>

    Remember to change “/path/to/secure/directory” to your path, and “username” to the the username you want. You can use any username you wish, and it does not need to exist as a UNIX user.

    Now we can create the username and password. The following command does this by creating a file called “.htpasswd” with the username and encrypted password inside.

    % /path/to/apache/install/bin/htpasswd -c .htpasswd username

    Again, remember to change “username” to the username you have chosen, and enter the password twice when prompted.

    Finally, we just have to make sure these two files are readable, and we are all done.

    % chmod 755 .htaccess
    % chmod 755 .htpasswd

    This directory and all subdirectories will now prompt for this username and password whenever they are browsed to.

    This entry was posted on Wednesday, August 3rd, 2005 at 10:05 am and is filed under Data and Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 3 Comments

    Take a look at some of the responses we've had to this article.

    1. This is a very concise and well written article.

      You might consider contributing it to The Tech FAQ as a standard Q&A.

    2. Feb 26th
      Reply

      Thanks!

      When I first did this, got a “server misconfiguration” error. Double checked my .htacess file and apache didn’t like the quotes around “Secure Document” I had copied from your post. I had to change them to regular ASCI quotes.

    3. [...] .htaccess file in your /wp-admin/ directory to require authentication before the page is displayed. This post provides the necessary [...]

  • Leave a Reply

    Let us know what you thought.

  • Name (required):

    Email (required):

    Website:

    Message:

Visitors have tagged this post: t (416) - apache password (313) - change apache password (116) - apache2 password (94) - simple .htaccess password (89) - apache set password (87) - htpasswd change password (84) - password apache (78) - apache change password (77) - Apache password protection (72) - simple htaccess password (67) - apache2 password protect (58) - apache password protect (52) - apache password change (46) - apache2 password protection (46) - apache2 htaccess password (44) - set apache password (41) - apache simple password (39) - apache2 protect directory (38) - apache directory protection (34) - apache2.2 .htaccess (34) - htaccess simple password (33) - password protect apache2 (32) - htpasswd change (32) - apache2 password directory (31) - set password apache (31) - change password apache (28) - apache +"protect directory" (27) - htpasswd howto (24) - htaccess samba (23) - apache htpasswd howto (23) - changing apache password (22) - .htaccess simple password (22) - how to change apache password (21) - apache2 .htaccess howto (21) - password apache2 (20) - change htpasswd (19) - apache passwords (19) - password protect apache (19) - apache2 password protect directory (18) - apache htpasswd change password (18) - password for apache (18) - easy htaccess password (18) - easy htaccess (18) - samba htaccess (17) - protect apache (17) - apache2 set password (17) - set password for apache (17) - htaccess password apache2 (17) - apache password htaccess (17) - password protect wordpress (15) - apache2 directory protection (15) - change password .htpasswd (15) - apache2 change password (15) - change password htpasswd (15) - easy apache (14) - samba .htpasswd (14) - apache2 password htaccess (14) - apache secure directory (14) - directory protection apache (13) - apache password directory (13) - htaccess password howto (13) - htaccess change password (13) - simple htaccess password protection (13) - secure directory apache (12) - password protection apache (12) - htaccess password simple (12) - create apache password (12) - f (12) - apache2 htpasswd howto (12) - change password in apache (11) - apache2 htaccess htpasswd (11) - password on apache (11) - simple password apache (11) - htaccess useradd (10) - apache password howto (10) - easy password protection (10) - apache htpasswd howto (10) - apache htaccess "change password" (9) - set password in apache (9) - password in apache (9) - simple apache password (9) - apache2 directory password (9) - how to set password in apache (9) - samba htpasswd (9) - apache htaccess passwd (9) - htaccess (8) - username (8) - apache password .htpasswd (8) - apache .htaccess password (8) - htpasswd apache2 (8) - set password on apache (8) - setting apache password (8) - how to change htpasswd (8) - apache setting password (8) - how to change password to get to website apache2 (8) - protect directory apache (8) - change .htpasswd (8) - setting password for apache (8) - apache password twice (7) - htpasswd apache howto (7) - change apache2 password (7) - apache password subdirectory (7) - apache2 password howto (7) - wordpress password protect directory (7) - apache2 htaccess (7) - apache change htpasswd (7) - apache password set (7) - apache 2 password (7) - apache2 passwords (7) - apache22 htpasswd (7) - apache2.2 password (7) - apache password protect subdirectory (7) - simple password protection apache (7) - apache change user password (7) - apache htaccess samba (7) - apache protect (7) - how to set apache password (7) - .htaccess password twice (7) - htpasswd samba (7) - apache2 .htaccess password (7) - apache protect directory (7) - wordpress htaccess password (6) - htaccess password subdirectory (6) - htaccess password apache (6) - password protect directory apache2 (6) - Wordpress password protection (6) - easy apache password (6) - htpasswd apache2.2 (6) - apache2 password protect directories (6) - apache2 password htpasswd (6) - apache protect subdirectory (6) - apache password protect directory (6) - simple htaccess protection (6) - simple password protection (6) - apache password simple (6) - apache simple password protection (6) - change password .htaccess (6) - change password with htpasswd (6) - protect apache with password (6) - apache change password htpasswd (6) - apache22 password (6) - change htpasswd password (6) - all (5) - samba password protect (5) - protect directory apache2 (5) - apache directory protect (5) - change password apache2 (5) - apache password protect subdirectories (5) - set password to apache (5) -