Add a basic authentication to apache2

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I want to enable basic authentication to this https://forum.tuteehub.com/tag/website">website configuration, i have also created a password file at https://forum.tuteehub.com/tag/location">location /etc/apache2/.htpasswd but I don't know how to add it to configuration file.

Here is my configuration file

 

    ServerName proxy
    ProxyPass / http://10.0.0.3:8080/
    ProxyPassReverse / http://10.0.0.3:8080/
profilepic.png
manpreet 2 years ago

 

The first time we use this utility, we need to add the -c option to create the specified file.

We specify a username (sk in this example) at the end of the command to create a new entry within the file:

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

You will be asked to supply and confirm a password for the user.

If we view the contents of the file, we can see the username and the encrypted password for each record:

cat /etc/apache2/.htpasswd

Output
sammy:$apr1$lzxsIfXG$tmCvCfb49vpPFwKGVsuYz.
another_user:$apr1$p1E9MeAf$kiAhneUwr.MhAE2kKGYHK.

Configure Apache Password Authentication

sudo nano /etc/apache2/sites-enabled/000-default.conf


    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

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

Save and close the file when you are finished.

Restart Apache to implement your password policy:

sudo service apache2 restart


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.