How to implement HTTP Authentication/Password protect your website in Apache

How to implement HTTP Authentication/Password protect your website in Apache

In this tutorial, we will describe the basics of password protecting a website using HTTP authentication.

Step 1. First, we need to create password which we will use to login to the site.

# htpasswd -c /home/passwords zoomtut
New password: #####
Re-type new password: #####
Adding password for user zoomtut

Step 2. Next, we’ll need to configure the server to request a password and tell the server which users are allowed access. In order for this to happen, we will edit .htaccess file in the root of the website and enter the below lines on top of the file.

# cd /var/www/html/
# vi .htaccess
AuthType Basic
AuthName "Restricted Files"
# (Following line optional)
AuthBasicProvider file
AuthUserFile "/home/passwords"
Require user zoomtut

Step 3. Let’s verify by browsing the site.

Enter username and password to browse the website:

Hurray! we are in the site.

This completes the tutorial for creating password protected website. Enjoy browsing.


Safi Ahmed Choudhury

Safi Ahmed Choudhury

Safi is the founder and chief editor of ZoomTutorials Blog, a leading tutorials and technology blogging site specializing in DevOps, SysAdmin and Cloud Technologies to help IT professionals in their day to day work. He is a Senior Cloud and DevOps Solutions Engineer at a leading eCommerce development Company and has more than 8 years of SysAdmin experience working with Fortune 500 companies to solve their most important IT backbones. Safi lives in Hyderabad with his wife and a son.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.