How to Password Protect a Directory

This process involves three parts:

Create a private directory outside of public_html to store the.htpasswd file in.

Create the .htaccess file in the directory to be protected.

Create the first user and the password file.

Note: Pay careful attention to which files start with a dot and which ones don't. This is not the only working procedure, as there are many complex authentication options, but if you are unsure what to do, this procedure will work.

Private Directory

Create a directory called "private" under your home directory. From a shell prompt, or command-line FTP prompt, the command is "mkdir private". From other FTP clients, check your documentation. If you already have a directory called private, and it already has a .htpasswd file in it, create a directory with another name.

.htaccess File

Enter the following information and save it as .htaccess. Be sure you put this into the directory you wish to protect. Note that this protects all subdirectories under this directory.
AuthUserFile /home/username/private/.htpasswd
AuthGroupFile /dev/null
AuthName "Any Name You Want"
AuthType Basic

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

Notes:

AuthName will be the name that appears in the authentication window when the user tries to access that directory. This is the window where they will enter their user name and their password.

Create the First User and the Password File

To create the initial password file for the first user:

  1. cd
  2. cd private
  3. htpasswd -c .htpasswd username

    NOTE: The -c creates the password file called .htpasswd

  4. Enter the password twice when prompted.

To change a password or add another user:

  1. cd ~/private
  2. htpasswd .htpasswd username
  3. Enter the password twice when prompted.

Note: Do not use -c to add more users, as it will create and overwrite the password file you created and wipe out your user information you first entered.

To remove a user:

  1. cd ~/private
  2. pico .htpasswd
  3. delete the line with the USERNAME you want to delete
  4. {CTRL} x
  5. y
  6. <ENTER>

 



http://www.tdl.com/bluline.gif

Why Us?

Address

Follow Us

Newsletter

All Rights Reserved
© Copyright 2017 TDL.com

Customer Support   855-TDL-HOST (855-835-4678)    -     TDL Solutions    -    Webmail