How do I password protect a directory in cPanel?
Introduction
The Directory password protection is a function of cPanel that allows you to protect a directory from unauthorized access. The function works by displaying a login form where the visitor must enter a username and password. If these are correct, the contents of the folder are displayed, otherwise an appropriate error message appears. This feature is especially useful if you want to protect confidential directories on your web hosting account, such as:
- Website admin directories: Directories like the admin directory for WordPress - for example wp-admin.
- Places with images or files that should only be displayed to authorized users
- Folder with downloads available only for authorized users
- Development copies of your website
Let's move on to the cPanel function "Directory Password Protection"!
Access to the directory privacy function
As mentioned earlier, "Directory Password Protection" is a cPanel feature and as such you will need to log into cPanel for your web hosting account to access it. If you are not sure how to log into your cPanel, please see our other tutorial on this topic - "Access to cPanel".
Within the cPanel service, the "Directory Privacy" function is available directly under the "Files" function category. This is called in our cPanel: Data protection for folders.

Once you click on the function, you will be redirected to a new page where you can configure the directory password protection.
Configure the Directory Password Protection function.
The newly opened page contains some basic information about what the Directory Password Protection function is, as well as a Directory listfrom which you can select the directory you want to protect.
As mentioned at the beginning of this tutorial, the Directory Password Protection feature protects folders that are Accessible only via the Internet are. This means that the protected directory is located under the directory root of either your Main domain or one of the additional Domains or subdomains that you have added to your web hosting account. If the protected directory is located outside the root directory of your domain, it will not be accessible and the purpose of the function cannot be achieved.
Now select a folder that you want to protect. In our case, this is the "admin" folder in the "public_html" directory of our example web hosting account.

To select a folder to be directory protected, you should click on the folder name or folder icon. After that click on EDIT.

Now you will be redirected to the last page where you configure the rest of the settings.
To enable "Directory Privacy" for the selected folder, you must first check the "Password protection for this directory"Activate. Specify the name of the protected directory.

When you are done, click the "Save" button to open the "Data protection for folders" to enable it. cPanel saves the configuration and displays a message that the "Folder Privacy" feature has been successfully enabled.

Congratulations! You have successfully enabled the "Directory Password Protection" feature! But that's only half the work. Now let's see how you can create a Create userwho is authorized to view the contents of this folder.
Creating a new user for access to the password-protected directory
As mentioned above, the "Directory Password Protection" function requires authorization in order to open a protected folder via the Internet. The authorization is done by entering a Username and password. To create this, you need to return to the password protected folder configuration.

The second part of the page serves User creation and assignment to access the password-protected folder. To create a new user, please enter the user name and password in the "Create user" section.

Once you have filled in the fields, please click the "Save" button so that the user can be created. cPanel will then create the user, assign it to the folder and finally issue a message indicating the successful operation.

Done! You can now access the folder through your web browser! If you forgot your password or want to change it, just go to the same configuration page of the password protected folder and add the user with the new password you want to use.
Congratulations, you now know how to fully protect a directory on your web hosting from unauthorized access. If you have difficulties in activating the protection, please contact our technical support.