How to protect an Apache Website with a password

This blog post assumes that Apache is already installed.

You’ll need to install this package in order to protect the website with a password.

sudo apt install apache2-utils

First of all, you’ll need to create a password file. In this example, a user called exampleuser is created into the password file /etc/apache2/.htpasswd. The command to create the file and the user is:

htpasswd -c /etc/apache2/.htpasswd exampleuser

You’ll need to add the following lines into the Directory directive related to the site you want to protect:

AuthType Basic
AuthName "Restricted Content"
AuthUserFile/etc/apache2/.htpasswd
Require valid-user

Leave comment

Your email address will not be published. Required fields are marked with *.

Time limit is exhausted. Please reload the CAPTCHA.