Basic apache2 username and password authentication

written by Admin

Posted on 2013-07-17


I must configure apache2 to ask username and password interactively to access a specific directory of my website.


Insert this text in /etc/apache2/sites-enabled/nnn-yoursite (note that the username_and_password database is outsite website public access directory):
<Directory /var/www/html/your_path/>
   AuthType Basic
   AuthName "Private Repository"
   AuthUserFile /etc/apache2/.htpasswd
   Require valid-user
   AllowOverride None
   Order allow,deny
   Allow from all

Then set username and password using this command:
# htpasswd -c /etc/apache2/.htpasswd your_username

When prompted for the password, insert it twice and reload apache configuration:
# /etc/inid.d/apache2 reload



Leave a Comment:



We need collaboration and a real boost from our community: write us an email for every trick you find!

This website is a sysadmin swiss-knife for every-day Windows, Linux and Mac administration and troubleshooting

Our database grows if YOU send us your tips and trick as soon as you find them every day!