This site utilizes JavaScript to function correctly. Looks like it's disabled on your browser. Please enable it for your best experience.

For instructions on enabling JavaScript, click here

Skip to main content

Just Host Web Hosting Help

Password Protect a File

Summary

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 using the Password Protect Directory tool in your cPanel.

This article will show you how to manually password protect a directory (folder) on your account.

Password Protect a Directory

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

In the .htaccess file will be statements such as the following:

    AuthType Basic
                AuthName "Restricted Area"
                AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
                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'. This is done by modifying the .htaccess statement as follows:

    <Files secure.html>
                  AuthType Basic
                  AuthName "Restricted Area"
                  AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
                  require valid-user
                </Files>

This can also be used to protect multiple individual files in directory, the method is very similar, however this time use Apache’s FilesMatch directive. This allows us to list as many files as needed:

    <FilesMatch "(secure\.html)|(secure\.txt)">
                  AuthType Basic
                  AuthName "Restricted Area"
                  AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
                  Require valid-user
                </FilesMatch>

Note: To add files, include more instances of “|(filename\.ext)”.

Knowledgebase Article 158,865 views bookmark tags: file passwd password prompt protect secure single


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

How do I password protect a folder on my website?
Knowledgebase Article 166,608 views tags: folder password protect

Accessing your account is as easy as entering your domain name and password on the login screen, or clicking one of our Single Sign-On options.
Knowledgebase Article 117,942 views tags: authentication factor login management password sign single sso

What should I do if I am having problems with multiple password prompts on my password protected directory?
Knowledgebase Article 115,288 views tags: folder password protect

Related Help Content

How do I change my Control Panel password?
Knowledgebase Article 1,155,660 views tags: change cpanel password passwords protect

How can I protect the images on my website?
Knowledgebase Article 172,340 views tags: click code image images javascript protect save saving script tips tricks

This article will explain how to change the password for a database in the event that the original password is lost.
Knowledgebase Article 127,339 views tags: database mysql password

How do I use a secure FTP connection?
Knowledgebase Article 238,254 views tags: ftp secure sftp shell ssh

This article explains the different password types for your justhost account.
Knowledgebase Article 107,908 views tags: billing cpanel hosting main password

The hosts file is a plain text file that allows you to set IP Addresses for a domain on your computer. This may override authoritative DNS.
Knowledgebase Article 12,492 views tags: admin development dns file hosts ip test

I am prompted to set a new MySQL password. What does this mean and how do I change it?
Knowledgebase Article 123,399 views tags: connect database mysql password phpmyadmin username

How to force https on entire website.
Knowledgebase Article 264,814 views tags: htaccess ssl website

** Google ad credits are only available to customers in the United States, Canada, and the United Kingdom at this time.

¹ VAT (Value Added Tax) is not included in our advertised price and will be charged separately and itemized on invoices and billing information. Standard VAT rates based on EU Member State regulations may apply. Learn more.