Skip to content

Tutorials cPanel Beginner1 min read

How to Password-Protect a Directory in cPanel

Lock a folder, staging site or admin area behind a username and password using cPanel Directory Privacy or .htaccess and .htpasswd.

By ZSOLNET Editorial Team Updated

Key takeaways

  • Directory Privacy adds HTTP basic authentication to a folder.
  • It's ideal for staging sites and private downloads.
  • Always combine it with HTTPS so the password isn't sent in clear text.

With Directory Privacy

  1. In cPanel, open Files → Directory Privacy.
  2. Click the folder name to navigate, then Edit next to the folder you want to protect.
  3. Tick Password protect this directory and give it a name (shown in the login prompt).
  4. Click Save.
  5. Under Create User, add a username and a strong password, then Save.

Visiting the folder now shows a browser login box.

With .htaccess (any Apache server)

Create the password file outside the public folder:

htpasswd -c /home/username/.htpasswds/staging alice

Then add to .htaccess in the folder:

AuthType Basic
AuthName "Staging"
AuthUserFile /home/username/.htpasswds/staging
Require valid-user

Frequently asked questions

Will Google index a password-protected folder?

No. Crawlers can't log in, so protected pages aren't indexed. That makes it a good way to keep staging sites out of search results.

Can I protect WordPress's wp-admin this way?

Yes, but exclude admin-ajax.php, which some front-end features call. Many prefer two-factor login instead.

Share X LinkedIn Facebook

Log in to your account

Manage your domains, hosting and invoices in one place.

Secure connection straight to the ZSOLNET client area.

No account yet?