How to create Apache htpasswd file in Linux OS?

by | 12 Feb 2017 | CentOS, Debian, Fedora, Linux, OS, RHEL, Server, Technology | 0 comments

What is htpasswd?

At times during web development, we will need to prevent the whole world from being able to access a particular website. That’s when Apache htpasswd comes into the picture. htpasswd is usually used together with htaccess.

Tutorial

This tutorial will teach you how to create a htpasswd file using command line.

Creating a htpasswd for the first time

htpasswd -c /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>

Example

htpasswd -c /var/www/yourdomain.com/.htpasswd themerv

Appending new user to existing htpasswd file

htpasswd /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>

Example

htpasswd -c /var/www/yourdomain.com/.htpasswd themerv

Using htpasswd in htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/yourdomain.com/.htpasswd
require valid-user

 

That’s it you are done!

0 Comments

Submit a Comment

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

Related Posts