How To Set Up Password Authentication in Apache2

sudo apt-get install apache2-utils

( FIRST USER only ( -c ) option to create file, or you will wipe all your existing logins !!! )

sudo htpasswd -c /etc/apache2/.htpasswd username1only

sudo htpasswd /etc/apache2/.htpasswd username2etc

Conventional setup
sudo vi /etc/apache2/sites-enabled/000-default.conf
( In which case you must specify the Directory to be protected )

<Directory "/var/www/">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

Alternatively setup, can be placed anywhere in the .htaccess file located in the webspace as desired ( multiple locations if desired ) using IfModule instead.

sudo vi /var/www/


AuthType Basic
AuthName "Ah! Ah! Ahhhhhh!"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

You may also like...