Ubuntu Linux: How to Add a User Account to a Specific Apache Password File CodeUnit 15 SEP 2009

Tux the PenguinThere are a variety of ways you can make private your Apache-driven web content, but without a doubt the most common way is simply to add a .htaccess file in the folder you wish to protect and add the following lines to it:

AuthName “Add your login message here.”
AuthType Basic
AuthUserFile /var/www/membersonly/.htpasswd
AuthGroupFile /dev/null
require user name-of-user

Of course, this is all very fine and well but now you actually need to be able to add and manage users that you wish to grant access to this folder to, meaning of course that you now need to edit the .htpasswd file. So how does one do this then?

Well the answer is the nifty little htpasswd command of course! An example usage of using htpasswd for this scenario would be:

sudo htpasswd -c .htpasswd craiglotter

… which would first check that the file exists, if not create it, then prompt for a password to be entered for the new user and the finally add a user account with the username of craiglotter.

Of course, htpasswd has a whole heap more functionality available to it, and if you want to check out its man page, you may as well start off here.

As always, have fun! :)

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.