Password Protecting Directories and/or Files with Bluehost

Password protect a directory

Step One: Sign in to your Bluehost Control Panel. Scroll to the Security section, click Password Protect Directories.

Control Panel > Security > Password Protect Directories.

Select the directory you wish to work with from the dropdown menu. Click Go. For this example, I will use the domain css-layouts.org and the folder rw-examples.

Bluehost password protect directory listing.
(Click image for larger view.)

IMPORTANT: If you have FrontPage Server Extensions installed, you will receive a warning that you cannot use the Control Panel to password protect your directories.
View Screenshot  You will need to either use FrontPage to password protect the directory, or turn off the extensions.

Step Two: From the list presented, select the folder name you wish to password protect.

View Screenshot

NOTE: When you select a folder to password protect, ALL of the files/folders within the selected folder will also be protected.

Verify that you are in the correct folder, then scroll down.

Step Three: Create a username and password for the protected directory.

NOTE: Make sure and create a secure password using letters, numbers, and special characters. You can also have a password generated for you.

Confirm the password you entered. Click the Add/Modify Authorized User button.

View Screenshot

The username and password have now been saved.

View Screenshot

Step Four: To activate the password, click 'Go Back.' You will now see your username on the Authorized Users list.

View Screenshot

Step Five: Select the checkbox to activate the protection.

Step Six: Name the protected directory. This name will appear in the message seen by visitors as thy access this directory. Click 'Save.'

View Screenshot

The following code (or something similar) will be added to your .htaccess file.

AuthName "Rootsweb"
AuthUserFile "/home/[username]/.htpasswds/public_html/css-layouts/rw-examples/passwd" require valid-user
AuthType Basic
require valid-user

Step Seven: Try and access the protected directory with your browser. You should be prompted for a 'username' and 'password.'

View Screenshot

Password protect a file

The easiest method of password protecting a single file on your hosting account is to first password protect the directory which contains that file. This can be done by following the tutorial Password protect a directory shown above.

When you Password Protect a directory, the system will place configurations into a file called '.htacess'. This file will be located in the folder that you protected.

Using our example, the following statements were placed In the .htaccess file:

AuthName "Rootsweb"
AuthUserFile "/home/[username]/.htpasswds/public_html/css-layouts/rw-examples/passwd" require valid-user
AuthType Basic
require valid-user

You will now need to modify the .htaccess file so that it applies the statements to a specific file. This is done with the following tags:

<Files [filename]></Files >

In this example, we will protect the file 'secure.html' that is located in the folder rw-examples which is part of the css-layouts.org domain. This is done by modifying the .htaccess statement as follows:

<Files secure.html>
AuthName "Rootsweb"
AuthUserFile "/home/[username]/.htpasswds/public_html/css-layouts/rw-examples/passwd"
AuthType Basic
require valid-user
</Files>

This can also be used to protect multiple individual files in directory. This would be done as follows:

<Files secure.html stillsecure.html members.shtml>
AuthName "Rootsweb"
AuthUserFile "/home/[username]/.htpasswds/public_html/css-layouts/rw-examples/passwd"
AuthType Basic
require valid-user
</Files>

 Try and access the protected pages with your browser. You should be prompted for a 'username' and 'password.'

Removing Password Protection

If in the future, you need to remove the password protection, follow these steps:

Sign on to the Control Panel Go to Security > Password Protect Directories

Click on the name of the directory you want to "unprotect." You should see a screen that has a checkbox next to "Directory requires a password...." Uncheck the box, and click Save.

View Screenshot


Download BlueHost Tutorials EBook.All of the BlueHost Tutorials have been assembled into one EBook in pdf format for easy printing. The file has been zipped for quicker downloading.



Copyright © 2010 by Expression Web Tutorials
Written and tested February 14, 2010
Updated November 2011