Oliver Nassar

First blog post in a while.. on htpasswd..

November 01, 2010

Still working out the kinks in my code (eg. no picture embedding just yet..) but this is my first post in about a year or so.. I'll post another shortly detailing why that was (the tech reasons of it mainly), but this is just a quick blurb on setting up mod_auth on your LAMP.

Ya, fun stuff I know.. So I have a protected zone on my server as follows:

<Directory "/var/www/dev.*">
    AuthType Basic
    AuthName "Development Server"
    AuthUserFile /var/www/auths
    Require user fred
    ErrorDocument 401 :(
</Directory>

I threw this in my apache config file, and wanted to quickly add a user to have access. I did it using the following command:

htpasswd -c /protected/pws username

Pretty straight forward. htpasswd is a small program that requires you to enter a file output location (eg. /protected/pws) and a username, and then prompts you as to what password you want for this user.

The -c flag tells it to create the file if it doesn't exist.