Home | About Us | Contact Us   
 

How to password protect a part of your web page:

1. In your home directory there is a directory called pubhtml. All your web files are supposed to go there. You are free to create subdirectories under that directory, just use the ftp command mkdir or use mkdir in a unix shell.

2. Let's suppose that your web site is jonnie.org, and there is a directory called /usr/home/jonnie/pubhtml/testdir which you want to protect with usernames and passwords.

3. First, you need to go to that directory, /usr/home/jonnie/pubhtml/testdir, and make a file called .htaccess - this name is obligatory; the web server won't recognize any access control files but .htaccess .

4. Next, you need to edit the .htaccess file to resemble this:

AuthUserFile /usr/local/www/data/jonnie.org/testdir/.htpasswd
AuthGroupFile /dev/null
AuthName "This test directory"
AuthType Basic

<Limit POST GET>
require valid-user
</Limit>

In this example, the fields mean the following:

AuthUserFile - a file containing information about users that have access to the directory you wish to protect, and their respective passwords.

AuthGroupFile - A file containing information about who is a member of user groups. Just leave it alone for this example.

AuthName - What the web server will call your testdir when it asks for a username and password. In this example it would ask: "Please enter your username and password for This test directory on http://www.jonnie.org/".

AuthType - Type of Authorization - currently only Basic is supported.

require - Tells the web server how to limit access to our testdir.

What you need to change:
AuthUserFile - It does not necessarily have to be called .htpasswd and don't forget to change the path name to match your domain.

5. Next you need to create a password file.

  • Change directory to /usr/home/yourid/pubhtml/testdir
  • Now we are going to create the .htpasswd file that you specified in the .htaccess file and locate it in testdir, in your pubhtml directory.
  • Do it by issuing the following command at the shell prompt(To Login to your Shell Prompt, see Getting Into Shell Account):
    /usr/local/bin/htpasswd -c .htpasswd myself
  • Enter a password for 'myself', re-enter it for verification.
  • A simple password file is created. To add another user just use:
    /usr/local/bin/htpasswd .htpasswd anotheruser
  • Enter a password for 'anotheruser', and re-enter it.
  • Now your password file has two user records.

6. Check that your password file works.

  • Put any .html file in your testdir, and point your browser to:
    http://www.jonnie.org/testdir/
  • The browser should ask you for a user name and password for "This test directory". Enter 'anotheruser' for username, and anotheruser's password that you entered when you were creating the password file in step 5. The server should let you read files in the directory.
  • If you enter an incorrect password and/or username - it should say something like "Authorization required to access..."

7. How to edit password file:

  • The password file is a plain text file, so you can edit it with any text editor, i.e. vi under unix.
  • To delete a user - just delete the corresponding line in the file.
  • To add a user - use htpasswd as described above.
  • To modify a user's password, use the same command you used when adding an additional user: "htpasswd .htpasswd usernamehere"

NOTE: Right now you have to ssh/telnet into your shell account to use htpasswd and create password files. You can not create it on your home computer and ftp it, like you can with your .html files.

For more information see the Apache HTTP server documents here: http://httpd.apache.org/docs/1.3/howto/auth.html

Please contact support@binary.net if you have any questions.

 
Copyright © Binary Net 1996-2005