Password Protect Directory in cPanel

There are always some parts on a website that a website owner wants to protect from anonymous users. For example, A directory that contains important data files. And sometimes, you have to keep those files inside the public directory of your website for you to access. Luckily, there is a way to password protect a directory in cPanel.

After enabling password protection on a directory, only a person with the right username and password combination can access the contents of a protected directory. In this short tutorial, I will show you how to password protect a directory in cPanel.

So, let us get started with the tutorial.

Password Protect a directory in cPanel

First of all, login to your cPanel account and find the Files section. In the files section, you will find a Directory Privacy option. Click on a Directory Privacy option.

Password Protected

Now, you will get a list of directories you have in your cPanel account just like the following screenshot.

Password Protected

You can navigate through the list of directories by clicking on a folder icon corresponding to the name of the directory. Finally, click on the name of the directory you want to protect.

After clicking on a directory name, you will be redirected to a new page that will look just like the following image.

password protect

On that page, click on the password protect this directory checkbox and enter the name of the directory. You can enter the same name. Finally, click on the Save button to password protect the directory.

Now, we have to create a username and password combination to access the protected directories.

CREATE A USER

Scroll down a bit and you will find a form to create a new user. In that form, Enter desired username and password combination. After filling up the required information, click on the Save button given at the bottom of the page.

Password Protected

Congratulations! Now try to access a password protected directory in your web browser. It will ask you for a username and password combination. Enter the correct username and password to access the contents of that directory. The bad username and password combination will result in 401 unauthorized access.

How to remove password protection

If you want to remove password protection on a password-protected directory. Click on a Directory Privacy option in the Files section of your cPanel.

Navigate to a password-protected directory and click on the name of that directory. Uncheck the Password protect this directory checkbox and click on the Save button given at the bottom of the form just like the following image.

Password Protected

Once done, the directory is no longer password protected. It means that anyone can access the directory content without any kind of authentication.

So, this is how you can password protect a directory in cPanel. Make sure to click on a folder icon to navigate through the list and click on a name to update the directory privacy. It is confusing if you are doing it for the first time. Let us know in the comment section if you have questions or queries. We will get back to you with help as soon as possible.

Important Notes with mod_rewrite

If your site uses mod_rewrite rules and redirects traffic to index.php to create urls, sub directories may have a non working password protect. To fix them edit .htaccess after creating the password protected directory outlined above and add

ErrorDocument 401 “Unauthorized Access”

RewriteEngine Off

For basic authentication, the server writes a 401 Unauthorized header and then looks for an error document based on a pre defined path. Most of the time, the error document won’t exist in the directory that you want to protect, so the request gets handled by the rewrite engine which throws a 404 error.

Was this answer helpful? 0 Users Found This Useful (0 Votes)