Basic HTTP Authentication with Apache 2
  Jul 16, 2009

Apache's HTTP Authentication is a fast and easy way to lock down a directory so that it prompts users with a password dialog box to view the files.

This guide assumes that you have Apache2 already up and running.

  1. <Directory "/path/to/web/dir">
  2.     AllowOverride AuthConfig
  3.     Order deny,allow
  4.     Deny from all
  5.     #Allow from 192.168
  6.     Allow from all
  7.  
  8.     AuthName "teh login"
  9.     AuthType Basic
  10.     AuthUserFile /usr/local/apache22/.htpasswd-name
  11.     Require valid-user
  12. </Directory>
  1. # htpasswd -c /usr/local/etc/apache22/.htpasswd-name username-to-use
  2. New password:
  3. Re-type new password:
  4. Adding password for username-that-you-used

Now restart Apache so the changes will take effect and visit the URL you added the authentication for and you should be prompted with a password prompt. Enter the login information setup with the htpasswd command from earlier.

  1. apachectl graceful
HTTP Auth Dialog Box



Post a New Comment

Name

Message

Security
Code

        (case insensitive & space between words)