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:

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


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.

  • 66 Users Found This Useful
Was this answer helpful?

Related Articles

What is FTP?

FTP (File Transfer Protocol) is a method used to transfer files between your computer and the web...

What is SSH?

SSH (Secure Shell) is a secure method for logging into a server remotely and giving the server...

How do I access cPanel?

cPanel can be accessed by using either of the URLs below:  ...

How do I find my MySQL version?

Login to cPanel In the "Stats" section on the left, locate the row labeled "MySQL Version"....

How do I find my PHP version?

Login to cPanel. In the "Stats" section on the right, located the row labeled "PHP version"....