Web - Password Protect Websites with .htaccess


2003-01-31

.htpasswd allows you to password protect websites. Lets say you want to protect files in your “public_html” folder.

$ cd /home/yourname/public_html
$ vi .htaccess

AuthUserFile /home/yourname/.htpasswd
AuthGroupFile /dev/null
AuthName GoAway
AuthType Basic
require valid-user

Next create the password file…

$ cd /home/yourname
$ /usr/local/apache/bin/htpasswd -mc .htpasswd username

(note: -c creates a new file deleting all data in .htpasswd. To create an additional account type “htpasswd -m .htpasswd username”)
Make sure all files are readable by Apache…

$ chmod 755 /home/yourname/.htpasswd
$ chmod 755 -R /home/yourname/public_html