Pages

Tuesday, January 1, 2013

apache2 basic auth

apache2 basic auth

This post assumes that you have installed apache2 server package in a Debian Linux and its running in port 80.

This post is about how to have basic folder authentication in Apache2.

By default, What ever data we put over /var/www are exposed to everyone.

We shall have  authentication for a particular folder under /var/www.

Create a directory under /var/www

Let us create a directory auth under /var/www

mkdir /var/www/auth

Now create an empty file with the name ".htpasswd-private"

touch  /var/www/auth/.htpasswd-private

Now run the following command to map the password to a Folder.

htpasswd /var/www/auth/.htpasswd-private newuser 
New password: 
Re-type new password:

Let us assume the password to be : password

Now edit the apache2 configuration file locate under
 /etc/apache2/apache2.conf

Add the following contents to the file.


<Directory "/var/www/auth>
AuthType Basic
AuthName "Private Documentation Repository"
AuthUserFile /var/www/auth/.htpasswd-private
Require valid-user
AllowOverride None
Order allow,deny
allow from all
</Directory>


Now restart the apache2 service.
/etc/init.d/apache2 stop

/etc/init.d/apache2 start

Now access open a browser and enter the address,
http://localhost


Now you can find that the folder "auth" will not appear.

We shall access the folder with the address,
http://localhost/auth




Now the browser will prompt for a user name and password.
Enter the User name as: newuser
Password: password

Now  we can see the contents of the folder and the folder will be 
displayed in main index page. (http://localhost) 




Reference:




No comments:

Post a Comment