Protecting a directory with a password using Apache and htaccess is really simple, I'll tell you how anyway.

Password Protect a Directory

Go to the directory you want to protect and create two files: .htaccess and .htpasswd (make sure you include the prefixed period (.)

If you are using ssh or the unix command line this is how you do it

touch .htaccess .htpasswd

Put this in the .htaccess file.

#Password protect current directory
AuthType Basic
AuthName "My Private Area"
AuthUserFile /fullpath/to/.htpasswd
require valid-user

Okay, now the tricky part, we have to make the .htpasswd file look like this:

nick:DIWN976v5sluf

Where nick is the username, colon is the delimiter, and DIWN976v5sluf is the md5 of the password.

I like to generate my passwords using the Linux command line, this is how:

htpasswd .htpasswd username

The above calls the htpasswd command, tells what file to put the username and password into, and gets the username (replace the username with the users actual name.

If you don't have access to a Linux terminal, just use an md5 generator.

How do I remove a user

Simple use the -D option.

htpasswd -D .htpasswd username

Reference

Comments

I really need to start looking into apache further.
I've got a question if you wouldn't mind: Every time I upload a .htaccess file it disappears from file view within the ftp browser. I assume this is because it is a hidden file (the prefixed period). Is there a decent work-around for this, or should I find a ftp client that is more apache-friendly (currently using cyberduck for mac os).

Thanks for your help!
Post Reply
Name *
Email (For verification & Replies)
URL
Code   
Submit Comment
Cancel
Excellent Question Calvin!

On Unix systems including Linux and Mac, a (.) before a file name tells the OS the file should be hidden.

Your lucky because I also use cyberduck. All you have to do is from the menu choose Cyberduck > Preferences > Browser and then choose Show hidden files.
Post Reply
Name *
Email (For verification & Replies)
URL
Code   
Submit Comment
Cancel
lerry
Not bad!
Post Reply
Name *
Email (For verification & Replies)
URL
Code   
Submit Comment
Cancel
Show/Hide Comment form