13 C
Texas

How To Configure Apache Web Page Authentication on Ubuntu / Debian

How can I secure an Apache Web page with password authentication on Ubuntu / Debian Web Server? How to use fundamental Authentication to restrict entry to specific Web pages on Apache? After installing and configuring your Apache Web Server, you need to configure password Authentication for a web page. This manual will cover a way to Install a password protected directory using fundamental Authentication. So, we will cover how to Configure Apache Web Page authentication on Ubuntu / Debian.

Apache Web Server can be set up on Ubuntu or Debian Server / Laptop by using firing the command below.

sudo apt update 
sudo apt -y install apache2

Check that Apache is running.

- Advertisement -
systemctl status apache2

You’ll see the following web page on the Server’s IP address/Host name.

Basic Apache Web Server Authentication Configuration

As you’ve installed Apache Web Server, now install Basic Authentication packages.

sudo apt -y install apache2-utils pwauth libapache2-mod-authnz-external 

Then create new configuration file for Apache under /etc/apache2/sites-available directory. And do the same as below.

sabi@Ubuntu:~$ sudo tee /etc/apache2/sites-available/secure-page.conf<<EOF
><Directory /var/www/html/secured>
>AuthType Basic
>AuthName "Basic Authentication"
>AuthUserFile /etc/apache2/.htpasswd
>require valid-user
></Directory>
>EOF

Then add users to the Basic Authentication file.

sudo htpasswd -c /etc/apache2/.htpasswd webuser
New password:
Re-type new password:
Adding password for user webuser

We use the -c option for the initial configuration, for next time we use:

sudo htpasswd -c /etc/apache2/.htpasswd osradar
New password:
Re-type new password:
Adding password for user osradar

Below file with users will be look like

cat /etc/apache2/.htpasswd

Now, it’s time to enable secure web. Run the command and you’ll see the following results

sudo a2ensite secure-page
Enabling site secure-page.
To activate the new configuration, you need to run:
systemctl reload apache2

Then create secure web directory.

sudo mkdir -p /var/www/html/secured

And then add the below data just for test purposes.

sudo tee /var/www/html/secured/index.html<<EOF
<html>
<body>
<div style="width: 100%; font-size: 50px; font-weight: bold; text-align: center;">
My secure web page - Using Basic Auth
</div>
</body>
</html>
EOF

Then restart Apache Services.

sudo systemctl restart apache2

After restarting apache services, test the web page to make sure that it is secure. So, type the below address in URL of browser.

localhost/secure

Or you can also use your IP address.

You will be asked to provide details as you have enter.

Then you’ll be directed to the secure Web Page.

So, this is how we can configure Apache Web Page Authentication.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article