Knowledgebase

How to password protect a folder in cPanel (Directory Privacy)

Sometimes you want a folder on your website to be private, for example a folder with documents for your team, a test copy of your site, or an admin area. With Directory Privacy in cPanel, the browser asks for a username and password before opening the folder. This guide shows you how to password protect a folder.

1) Open Directory Privacy

In cPanel, go to the Files section and click Directory Privacy (1).

Directory Privacy in the Files section

2) Choose the folder

Click the folder name to open it (for example public_html), then click Edit (1) next to the folder you want to protect.

Directory Privacy: choose the folder and click Edit

3) Turn on the protection

  1. Tick Password protect this directory (1).
  2. Write a name for the protected area (2), for example "Private Documents". It appears in the login window.
  3. Click Save (3).

Password protect this directory, name and Save

4) Create a user who can open it

Go back to the same folder. Under Create User write a Username (1), the New Password (2) and repeat it (3), then click Save (4). Give these details only to the people who need access.

Create user for the protected directory

Now open the folder address in the browser (for example https://yourdomain.com/private-docs); a login window appears.

Common problems

  • The whole site asks for a password → you protected public_html itself. Remove the tick from it and protect only the sub-folder.
  • WordPress shows errors after protecting wp-admin → WordPress uses wp-admin/admin-ajax.php for visitors too. Protecting wp-admin needs an extra rule; open a ticket and we will set it correctly.
  • The password does not work → check the username is exactly the one created for this folder, not your cPanel username.

Frequently asked questions

Is this protection secure?

Yes, when your site uses https, because the password is sent encrypted. Make sure you have SSL.

Can I add more than one user?

Yes, create as many users as you need and delete them when they no longer need access.

Do sub-folders get protected too?

Yes, everything inside the protected folder is protected.

Need help? Open a support ticket or message us on WhatsApp +20 127 113 3655.

  • password protect, directory privacy, cPanel, security

Was this answer helpful?

0 Users Found This Useful