Monday, January 19, 2015

Password Protection with htaccess




You can protecting directory on apache web server so no unauthorized people may access it, in here we would like use .htaccess file (there is DOT at front htaccess file name) on apache root directory.

root:# cat .htaccess
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/apasswords
Require user anjani
root:# ls -al .htaccess
-rw-r--r-- 1 root root 103 Oct  9 08:38 .htaccess


Make password for user anjani and save it on file /home/apasswords


root:# htpasswd -c /home/apasswords anjani
New password: ******
Re-type new password: ******
Adding password for user anjani
root:# cat /home/apasswords
anjani:jBdra06B5M54.


The password on the appasswords is encrypted


root:# ls -al /home/apasswords
-rw-r--r-- 1 root root 21 Oct  9 14:18 /home/apasswords
Done.