Creating Password Protected Directories in OS X Server Tiger

Originally Posted on BinaryEquine.com

I just set up some message boards that I only want to let a few select people use. Now I could have probably set something up so that you would have to be a registered member to see any content posted on the message board but for the purpose of educating myself (and hopefully you too) on how to password protect directories on your web server I choose to do something else.

First off you should be semi-familiar with the Terminal application. I will provide you with the exact command you need to create one of the files needed. You should also be familiar with OS X Server since this is what this will apply too!

First, open up a text editor. Next copy and paste the follow into the empty file:

AuthName “auth”
AuthType Basic
AuthUserFile /Library/WebServer/Documents/directory/where/password/is/kept/.htpasswd
require valid-user

For the line: AuthUserFile /Library/WebServer/Documents/directory/where/password/is/kept/.htpasswd, you’ll obviously want to change that to where you’re actually going to keep the file with the password in it.

I had the most luck with keep it in the main web server directory. I put mine in the actual directory I was protecting. The password you set does get hashed so it’d be near impossible for anyone to figure it out. So now that you have created and added in the contents to this file, save it as .htaccess. You might get an error or warning on saving of the file but just choose to use the . in the beginning of the file name. Make sure you saved this file in the directory you want to protect, this is important! Now we have created the file that tells the web server we want to password protect a directory.

The next step is making the password. Open up Terminal (found in Applications >> Utilities). Then move to the directory where you saved your .htaccess file by using the following command:

cd /Library/WebServer/Documents/admin/

Your command might be different, the above is just an example. The root of your web server is:

/Library/WebServer/Documents/

To make the password file you can copy and paste this command into Terminal:

htpasswd -c .htpasswd [username]

Example:

htpasswd -c .htpasswd admin

You will then be prompted to input a password, and then to confirm the password

This will create a file with the username admin and whatever password you chose. You can change the username to anything you would like though and use whatever password you want. This file will be saved right into the directory you want to protect so long as you ran the command from that directory.

So now you have your 2 “protection” files but there’s one last step. In Terminal navigate to your web server configuration directory:

cd /etc/httpd/sites/

Now type:

ls

You should get a list of files. These are the configuration files of the web sites on your server. I had about 5-6 of these files but you may only have one, they look something like, ‘0003_any_80_horse13.com.conf’. Type in:

sudo nano [name of config file]

You will enter a command line text editor after inputting your administrative password. This is a system file so you will need administrative access to edit and save it.

The command line text editor isn’t so bad! You will need to find the line that looks something like:

AllowOverride None

it’s about 30 lines down or so. Change it to:

AllowOverride All

You can save it by hitting Ctrl+O and then you can exit by hitting Ctrl+X. You can now use the GUI tool, Server Admin to restart your web server.

Go to the website you’re trying to password protect in your web browser and it should now prompt you for a username and password each time you access that directory/site.

Similar Posts

  • De-authorize your iTunes Account Before Hardware Repair or Sale

    Pretty much everyone has downloaded media from the iTunes store, but not too many of us know just how iTunes keeps track of computer authorization. Every device on the internet has at least two unique identifiers: a MAC address and an IP address.

    MAC is an acronym for Media Access Control. Many believe that Mac, the abbreviation for Macintosh, should be written with capital letters – this is incorrect. Likewise, iPod – not iPOD or IPOD; iMac – not iMAC or IMAC; etc. Network interfaces have MAC addresses; Macintoshes can be called Macs.

    Since your MAC address is completely unique, it’s the ideal way for iTunes to know that you’re authorized to play purchased content on any given machines. Trouble is, your ethernet port is part of the main logic board, which requires replacement in some repairs. With a new main logic board comes a new MAC address, which confuses iTunes and some other, generally high-end, software.

    You’re allowed to authorize up to five computers at any one time to play your purchased content, but replacing your logic board changes the MAC address. If you didn’t de-authorize before repair, you’ve lost 20% of your available authorizations. I made this mistake a few years ago when I had to replace the logic board in a Mac Mini hooked up to my television, and when I sold my iBook. I also lost an authorization when my two-week-old PowerBook G4 flew off the roof of my car at highway speed. Thankfully, iTunes allows you to de-authorize all computers on your account once annually.

    I only have one Machine these days, a 17-inch MacBook Pro, so this hasn’t been a problem of late for me. It’s a common question asked our technical support team, and a good fix to file in your troubleshooting arsenal.

    The full details from Apple can be found here: http://support.apple.com/kb/HT1420

  • Security on the Mac

    by Matt@Smalldog.com (posted By Ed, written by Matt@Smalldog.com) A very vigilant customer bought a new Mac Mini over the weekend at our Burlington…

  • You Don't Say….

    People have been talking (occasionally with expletives) to their computers since way before they could listen. And while speech-to-text has been technically feasible…

  • Calibrate that Battery!

    A while ago, we ran a tip about calibrating your MacBook, Macbook Pro, PowerBook or iBook battery. Keith at Small Dog suggested it…