How to Password-Protect a Directory in cPanel
Sometimes you want a folder on your site to be visible only to people you trust — a staging area, an admin tool, or a set of private downloads. cPanel's Directory Privacy feature puts a username-and-password prompt in front of any folder, so the browser asks for credentials before showing anything inside.
Step 1: Open Directory Privacy
- Log in to cPanel.
- Under the Files section, click Directory Privacy.
- Browse to the folder you want to protect and click its name.
Step 2: Turn on protection
- Tick Password protect this directory.
- Give the protected area a name (this shows in the login prompt).
- Click Save.
Step 3: Create a user who can get in
Protection is useless without someone allowed through, so add at least one user:
- In the Create User box, enter a username and a strong password.
- Click Save.
Use a genuinely strong password here — see creating strong passwords. Now visiting that folder pops up a login box, and only your users get in.
What happens behind the scenes
cPanel creates .htaccess and .htpasswd files in the folder to enforce the login. If you like editing by hand, our guide on creating and editing .htaccess files shows where these live (remember to show hidden files to see them).
Frequently asked questions
Is this secure enough for sensitive data?
It is good for keeping casual visitors and search engines out of a folder. For truly sensitive material, combine it with SSL so the login itself is encrypted, and consider proper application-level authentication.
Will search engines still index the folder?
No — they cannot get past the login, so protected folders stay out of search results. This makes it handy for hiding a staging site.
I locked myself out. How do I remove protection?
Go back into Directory Privacy, untick the protection box for that folder, and save. If you cannot reach cPanel at all, open a support ticket.
Was this article helpful?