What I will be describing here is how to password protect on a UNIX-based system, okay? Let's get started!
htpasswd -c /home/tomcat/.htpass tomcat
| |__________________| |____|
Specifies a | |___This is the user name that is allowed
new password | access to this directory.
file. |
|__________This tells the program where to put the
password file. Here, I have called the
file ".htpass". However, you can specify
the name of the file to anything you wish.
If you noticed, I put "/home/tomcat/" just before the name of the password file that I wish to have created. If you are running the
htpasswd program from "/usr/local/etc/httpd/support", you have to specify this because you probably do not have privilages to write to that directory.
To make it easier, you should run it from your home directory by typing in:After you have entered in that command line, it will ask you for the password for this user. You will have to enter it in twice, so make sure you spell it correctly, and use any upper/lowercase letters where you desire them. The password IS case sensitive.
Do not use numbers in your password. For some reason,it becomes transparent when comparing your entry to the password on file.
AuthUserFile /home/tomcat/lock/.htpass* AuthGroupFile /dev/null AuthName Secured Files AuthType Basic <Limit GET> require user tomcat require user johndoe require user janedoe </Limit>*AuthUserFile is the location of the PASSWORD file. Do not store it in the same directory that you are protecting.
In this example, I have 3 users that have access to this directory. When the user enters his/her username with the correct password, they are granted access.
The AuthGroupFile
If you know anything about a UNIX system, you are aware of the file /etc/group (if you don't know what I'm talking about, don't worry, I'll get to it). The web side can have a similar setup. If you plan on having a large number of users access to a password protected directory, the AuthGroupFile option may be for you.
You still need to create the users and their passwords, though. In addition to that, you'll also need to create a group file (ie .htgroup). That file will look like this:
WebGroup: janedoe johndoe HtmlGroup: webmaster tomcat
AuthUserFile /home/tomcat/lock/.htpass AuthGroupFile /home/tomcat/lock/.htgroup AuthName Secured Files AuthType Basic <Limit GET> require user tomcat require group WebGroup </Limit>Now, anyone in the group WebGroup has access to this directory. If you add more users, you'll only have to add them to the .htgroup file (in their appropriate group, of course), and not even have to touch the .htaccess file again! Also, as you can see, you can have user and group access in the .htaccess file.