How to Password Protect your Website using .htaccess
Apache authentication can be configured to require site users to login with a user id and secret key. Secret key securing a directory on your site is very simple. Website admins normally need to secure a directory in the event that they have data that they need to make accessible just to a chose number of people.
See Also:
Apache configuration files:
RedHat / Fedora / CentOS: "/etc/httpd/conf/httpd.conf" SuSE: "/etc/apache2/httpd.conf" Ubuntu / Debian: "/etc/apache2/apache2.conf"
Follow below steps to protect your website with a Password Using .htaccess:
Step #1: Create a .htaccess file
First access the directory you want to protect with password. Create .htaccess file and add below entries:
# cd /home/techoism/public_html/Admin/ # vim .htaccess
AuthName "Private" AuthType Basic AuthUserFile /home/techoism/public_html/.htpasswd require valid-user
Note:
Step #2: Create the Password File
If you don’t current have an .htpasswd, use the “-c” option to create the file with the first user. It will prompt you for a password and encrypt it for you.
# htpasswd -c /home/techoism/public_html/Admin/.htpasswd dennis
If you already have the .htpasswd file and would like to append a new user run the following command:
# htpasswd -m /home/techoism/public_html/Admin/.htpasswd steve
Step #3: Verify the Configuration
Now you can verify the configuration on your browser by running below domain:
http://127.0.0.1:8000 Or http://Server-IP
Enjoy it!