X

Basic password protection for Apache2 on Ubuntu

This is a relatively trivial topic, but comes up quite often. For securing content on a server, you’ll often want to password protect entire domains or paths. Add the following to the correct block in your httpd.conf and you should be ready to go.

If you have a complex environment, you may want to consider having individual password files for each asset.


<Location />
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>

To create/clobber a new file for the first user:
sudo htpasswd -c /etc/apache2/.htpasswd YOURUSER

To add additional users:
sudo htpasswd /etc/apache2/.htpasswd YOURUSER
(repeat for new users without the -c as that creates/clobbers the file)

Related Post