Htpasswd and Htaccess


If you would like to have a set of web pages that are protected, requiring a username/password to gain access, this tutorial will show you how to set it up.


Using htpasswd and htaccess in public_html


Step 1.


First you need create file with usernames and passwords


 ‘-c ‘ use only ones to create password database

htpasswd -c /home/user_name/password_file any_username


New password:

Re-type new password:

Adding password for user any_username


## another user

htpasswd /home/user_name/password_file mark


Step 2.

Now go to public_html  and choose folder which you want protect  and create folder called .htaccess

~/public_html> ee .htaccess


## .htaccess

Authname "Protection"

authtype basic

authuserfile /home/user_name/password_file

require user any_username marek


or you can use option require valid-user  to let multiple users



Step 3.(optional)


Password cryptographic methods


# Crypt method

htpasswd -d /home/user_name/password_file mark


# MD5

htpasswd -m /home/user_name/password_file mark


# SHA encryption

htpasswd -s /home/user_name/password_file mark




Live Free Or Die!