How to password protect a single file?

In order to password protect a single file, you need to have the following files under your account:

 

.htpasswd (containing the username and password through which the file can be accessed)

.htaccess (containing the authentication rules)

 

You can create both files through your cPanel > File Manager.

 

You should follow these steps:

 

1) Do NOT create the .htpasswd file below your public_html directory. Otherwise it will be
accessible through http requests. We would advise you to use the
root folder for your account - /home/username/ (where username is your cPanel username).

In this file you should put the encrypted password for your username. This can be
done using the following username/password generator:

http://www.htaccesstools.com/htpasswd-generator/

2) Put the .htaccess file in the directory of the file that you
wish to be protected. Please note that .htaccess files work recursively
therefore those changes will affect all the subfolders in the directory
that you have placed the .htaccess file in. Once the .htaccess file is in place, the
following lines should be added to it:

<FilesMatch "file.html">
AuthName "Member Only"
AuthType Basic
AuthUserFile 
/home/username/.htpasswd
require valid-user
</FilesMatch>

In the <FilesMatch "file.html"> part you specify the criteria for
protecting your files. You can choose a single file:

<FilesMatch "file.html">

or files from different types but with the same name:

<FilesMatch "file.*">

In the AuthUserFile /home/username/.htpasswd part you should change username to your cPanel username.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Brute Force Attack – What it is and How to Block It

Brute-force is a method of guessing your password by trying combinations of letters, numbers and...

What is pdftoppm and is it supported by Hostlantern?

Pdftoppm is a library that handles the conversion from Portable Document Format (PDF) files to...

How to clear your Internet browser’s cookies?

Sometimes you may need to clear the cookies saved by your browser. Basically the cookies...

Hacked Website

The most common reasons for a hacked (defaced) website include: - Outdated web application....

How to clean my files from malicious code?

If your website has been hacked and malicious content has been inserted into your files, you...