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
Related Posts:
- Install Awstats 6.5 Without Ports
- Exclude a Sub-directory in Tar Command
- Create MySQL User
- Move Apache Log Files
- Move a Server
- Stop the Most Annoying Spammers
- Install Awstats on FreeBSD
- Apache and Google
Filed Under: Apache
May 15th, 2006 at 4:36 pm
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