.png&w=3840&q=75)
Websites & Hosting3 min
How to Password Protect Web Directories in cPanel
NS
NameSilo Staff9/2/2026
Share
To password protect a web directory in cPanel, open the Directory Privacy tool under the Files section. Select the folder you wish to restrict, check the box "Password protect this directory," name the security zone, and create authorized user accounts with custom passwords. This places an HTTP authentication shield over the selected folder.
How HTTP Basic Authentication Locks a Directory
Directory Privacy is a graphical front end for a decades-old Apache mechanism: .htaccess combined with a .htpasswd file. When protection is enabled, cPanel writes authentication rules into the folder's .htaccess and stores encrypted credentials in .htpasswd, kept outside the public web root for security.
The result is a hard stop at the server level. Before Apache serves a single file from that folder, a browser popup demands a username and password. This happens before your application, WordPress, a custom script, anything, ever runs. It's a wall in front of the wall.
Why It Matters: Keeping Sensitive Content Out of Public View
An unreleased staging build, a private client portal, or an internal admin tool sitting in a public folder is reachable by anyone who finds the URL, including search engine crawlers that will happily index it. Directory Privacy closes that gap entirely: no valid credentials, no access, no matter how the URL was discovered.
Step 1: Navigating Directory Privacy
In cPanel, go to the Files section and click Directory Privacy. Browse to the target folder (for example, public_html/staging) and click Edit next to it.
Check "Password protect this directory", and enter a descriptive Realm Name, the text visitors see in the browser's authentication popup. Something like "Staging Environment" is more useful to legitimate users than a generic label. Click Save.
Step 2: Creating Authorized Users
After saving, a Create User section appears on the same page. Enter a username and a strong password (cPanel's built-in password generator works well here), then click Save. You can add multiple authorized users to the same directory if more than one person needs access.
Common Mistakes
Password protecting public_html itself instead of a subfolder: This locks your entire public website behind an authentication prompt, blocking every visitor and every search engine crawler simultaneously. Always target the specific subfolder that actually needs restriction.
Protecting /wp-admin/ without accounting for AJAX: If you password-protect a WordPress site's wp-admin directory, admin-ajax.php needs an explicit exception, or AJAX-dependent plugins and dashboard features stop working. Add this to the folder's .htaccess before the WordPress block:
<Files admin-ajax.php>Order allow,denyAllow from allSatisfy any</Files>Even with this exception, some AJAX and REST API calls can still intermittently fail, since requests originating from browser JavaScript don't always carry the Apache authentication headers correctly. Plugin updates and caching plugins can also misbehave under this setup. For most sites, it's safer to password-protect a narrower subdirectory, like a private uploads folder, rather than /wp-admin/ directly.
What This Means for You
NameSilo Hosting includes full cPanel access with Directory Privacy ready to use for securing staging folders, client portals, or admin areas on your shared hosting environment.
Frequently Asked Questions
How do I password protect a folder in cPanel?
Files → Directory Privacy → select folder → check "Password protect this directory."
What is Directory Privacy in cPanel?
A tool generating .htaccess/.htpasswd HTTP authentication for a chosen folder.
What is an .htpasswd file?
A file storing encrypted credentials for directory-level authentication.
Does password protecting a directory block search engines?
Yes. Crawlers cannot authenticate and will not index the content.
How do I remove password protection from a folder?
Return to Directory Privacy, edit the folder, and uncheck the protection box.
Can I create multiple usernames for one protected folder?
Yes. Add as many authorized users as needed in the Create User section.
Why is my .htpasswd file not working?
Check file paths in .htaccess and confirm hidden files are visible in File Manager.
Does NameSilo hosting support directory privacy?
Yes, included with cPanel access on all NameSilo hosting plans.
.png&w=2048&q=75)
NameSilo StaffThe NameSilo staff of writers worked together on this post. It was a combination of efforts from our passionate writers that produce content to educate and provide insights for all our readers.
More articleswritten by NameSilo

.png&w=3840&q=75)
.png&w=3840&q=75)
.png&w=3840&q=75)