public_html, and on WordPress leave admin-ajax.php reachable if you protect wp-admin.What Directory Privacy does
Directory Privacy, called Password Protect Directories in older cPanel versions, adds HTTP basic authentication to a folder. The browser shows a login box before any file in the folder, or its subfolders, is served. It is useful for:
- A staging or development copy of a site that should not be public or indexed.
- A folder of private downloads for clients.
- An extra login in front of an admin area.
Step 1: choose the folder
- Log in to cPanel and open Files > Directory Privacy.
- Browse to the folder. Click a folder name to open it, or click Edit next to it to protect it.
Create the folder first in File Manager if it does not exist yet.
Step 2: turn on protection
- Tick Password protect this directory.
- Enter a name for the protected area, for example Staging. Browsers show it in the login box.
- Click Save.
Step 3: create users
- In the Create User section, enter a user name.
- Enter a strong password, or use the password generator.
- Click Save. Add more users the same way.
These users are separate from your cPanel login and email accounts. They only open this folder.
How it works behind the scenes
cPanel adds lines like these to the folder’s .htaccess file, and stores the users and encrypted passwords in a file under /home/USERNAME/.htpasswds/, outside the public web folder:
AuthType Basic
AuthName "Staging"
AuthUserFile "/home/USERNAME/.htpasswds/public_html/staging/passwd"
require valid-user
Use HTTPS
Basic authentication sends the user name and password with every request. Over plain HTTP they can be read on the network. Make sure the site has a valid SSL certificate and redirects to HTTPS before you rely on Directory Privacy.
Protecting the WordPress admin area
An extra password on wp-admin blocks many automated login attacks. WordPress uses wp-admin/admin-ajax.php for features on the public site, so allow that one file. Add this to wp-admin/.htaccess after cPanel’s lines:
<Files "admin-ajax.php">
Require all granted
</Files>
For other ways to protect the login page, see our guide to changing the WordPress login URL.
Directory Privacy or another option?
| Need | Best tool |
|---|---|
| Keep a staging site private | Directory Privacy, plus a noindex setting in the CMS |
| Block one troublesome visitor | IP Blocker |
| Allow only your office | An IP allow rule in .htaccess, or IP Blocker for everyone else |
| Members-only content on a live site | A membership plugin in your CMS, with its own user accounts |
Basic authentication is simple and reliable, but it has no password reset, no logout button and no per-page control, so it is best for small groups of trusted users.
Remove protection
- Open Directory Privacy and click Edit next to the folder.
- Untick Password protect this directory and save.
- Delete users you no longer need in the Authorized Users list.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| The login box keeps coming back | Wrong password, or the user was not saved | Reset the user’s password in Directory Privacy. |
| WordPress shows 404 instead of the login box | WordPress rewrite rules catch the 401 response | Add ErrorDocument 401 default to the folder’s .htaccess. |
| The whole site asks for a password | public_html itself was protected | Protect the subfolder only, and remove protection from public_html. |
| 500 Internal Server Error | A mistake in a hand-edited .htaccess | Remove the extra lines, or turn protection off and on again in cPanel. |
Need help with this?
Need a private staging site? Create one on our hosting and protect it in a few clicks.
Frequently asked questions
Where is Password Protect Directories in the new cPanel?
It is called Directory Privacy, under Files.
Does Directory Privacy protect subfolders?
Yes. Protection applies to the folder and everything inside it.
Is basic authentication secure?
It is secure enough for staging sites and private folders when used over HTTPS with strong passwords.
Can I password protect my whole website?
You can, for example while building it, but visitors and search engines will not see the site until you remove it.
Are Directory Privacy users the same as my cPanel login?
No. They are separate users that only open the protected folder.
Related guides
- How to Reset a WordPress Admin Password (Email, WP-CLI or Database)
- How cPanel Redis Manager Brings Faster Application Performance to Your Server
- How to Use Redis Manager in cPanel to Boost Website Speed
- How to Use cPanel’s File Manager to Manage Your Website
- Top cPanel Security Tips to Keep Your Hosting Environment Safe
