This tutorial will setup basic authentication using Apache running on Ubuntu 18.04.
Assumptions:
- You have configured Apache2 under Ubuntu 18.04 LTS
- Clean install as we are going to erase any and all configurations in
/etc/apache2/sites-enabled
- Your using the
root
account or your account has been added tosudo
group. - Have
vi/vim
installed
Note: If your running this as a root account, such as in a docker container, remove all the sudo calls.
Generating a User and Password
From the terminal run the following command:
|
|
When prompted for a password enter one.
Verify from the terminal that .htpasswd
was generated at /etc/apache2/.htpasswd
, you can do this by navigating to the directory and checking or run the following:
|
|
Configuring Virtual Host
For this tutorial we are going to use the following script to generate our virtual host file that will enable authentication. It is a modified version of the default configuration found in /etc/apache2/sites-enabled
.
Note: This script will setup the default apache2 sites-enabled file to use your newly created .htpasswd
username/password. This will create a backup of your current sites-enabled
folder to /etc/apache2/sites-enabled/sites-backup/
for you to restore if something breaks.
|
|
Verifying Setup
Verify your installation by visiting http://localhost and verify that you are prompted for a username and password to continue. Check the credentials created in Generating a User and Password work for validating.
Congratulations, you know have a working implementation of basic HTTP authentication using Apache and Ubuntu 18.04.