FreeBSD Server Administration

« How to Transfer a Website Effectively | Main | Tar Command »

April 09, 2005

Protect Directory

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.
This step may not be necessary. If there is an entry about the directory you want to protect 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
# /usr/local/sbin/apachectl restart


Category : Apache

Posted by FreeBSD Newbie at April 9, 2005 11:54 PM

Comments

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

Posted by Luda at May 15, 2006 04:36 PM

Post a comment



(Optional, will not be shown to the public)

Remember Me?