Ubuntu Linux: How to Add a User Account to a Specific Apache Password File

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! :)

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Technology & Code, Tutorials. Bookmark the permalink.
    blog comments powered by Disqus