Apache htaccess Linux

Password protecting an Apache Server

If you need to protect a web server so that a folder cannot be access without entering a password first.

First ensure that the option is turned on

vim /etc/apache2/sites-available/default


AllowOverride None


AllowOverride All

Now, create a .htaccess file

AuthUserFile /var/htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user

Instead of “valid-user”, you can enter the usernames you want.

Finally create a password file. For each user, replace “username”

htpasswd -c /var/htpasswd username

You will need to double enter the password.

Finally, restart apache

service apache2 restart


Leave a Reply