Saturday, February 6, 2010

How to set up Apache with groups of users and basic HTTP authentication

1. Do this as user root:

sudo su -

and find the path to the config files for Apache, ex: ls -la /etc/apache2/

2. create users, and use the htpasswd tool to encrypt their passwords
and store them in the password file:

htpasswd /etc/apache2/passwords john

and

htpasswd /etc/apache2/passwords mary


3. add your users to a groups file

nano /etc/apache2/groups

Create a group called "trusted" followed by ":" followed by
the user names who are in that group, space delimited:

trusted:john mary


and set permissions so that user apache (who is in group "www-data")
can actually see the "passwords" and "groups" files.

chown root:www-data /etc/apache2/groups
chown root:www-data /etc/apache2/passwords


4. edit the apache config file to set up the directory which you are serving

nano /etc/apache2/apache2.conf

At the end of the Apache config file, add the following alias,
assuming that you keep all your files in /home/john/coolfiles/


alias /john "/home/john/coolfiles"

Options Indexes +MultiViews
AllowOverride None
Order allow,deny
Allow from all

AuthType Basic
AuthName "Password Required"
AuthUserFile /etc/apache2/passwords
AuthGroupFile /etc/apache2/groups
Require Group trusted




5. restart apache, as user root

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start



6. test with a browser

http://localhost/john/

or

http://yourdomain.com/john/



Share

No comments:

Post a Comment