Home > Apache > Protect Directory

Protect Directory

April 9, 2005 Posted by KP

How to protect a directory under Apache?

This can be done with .htaccess, visitors must input username and password before they can access the protected directory.

Step 1.
Create the file “.htaccess” with the following content under the directory you want to protect, you can specify the password in any place as long as Apache can access it.

AuthUserFile /home/account/passwd/.htpasswd
AuthGroupFile /dev/null
AuthName “Title”
AuthType Basic

<Limit GET POST>
require valid-user
</Limit>

Step 2.
Generate the password file “.htpasswd” under the directory /home/account/passwd/ with the following command:
# htpasswd -c .htpasswd user_name

You will be reminded to input password for the user “user_name”, this command can be called multi times to generate multi users.

Step 3.
Usually this step is unnecessary. If there is an entry about the directory in Apache configuration file, make sure AllowOverride has the option authconfig.

For example, when protecting Awstats pages, the Apache configuration file should be modified as following:

<Directory “/usr/local/etc/awstats/wwwroot”>
Options None
AllowOverride authconfig
Order allow,deny
Allow from all
</Directory>

Restart Apache if you have done step 3:
# /usr/local/sbin/apachectl graceful

Bookmark and Share


Related Posts:

Filed Under: Apache

One Comment to “Protect Directory”

  1. Luda Says:

    Hello,
    I’m running apache2 under RedHat 8, using mod_ntlm2 for NT domain.
    When mod_ntlm uploaded, it doesn’t allow basic authentication
    which I use for selective directories using .htaccess
    Here my .htaccess file:

    AuthName ByPassword
    AuthType Basic
    AuthUserFile

    require user admin

    What is the exact directive to configure .htaccess
    co-exist with ntlm mode?
    Any help appreciated & thanks in advance.

    Luda

Leave a Comment









*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Categories

Archives

Links

  • Dedicated Servers
  • Meta