UnderHost
Knowledgebase Docs

How to password protect a directory in cPanel

Restrict access to a folder on your website using HTTP Basic Authentication. Use cPanel Directory Privacy or .htaccess to require a username and password.

On this page

Password protecting a directory adds an HTTP authentication prompt to a folder on your site. Visitors see a browser login dialog before they can access the content. Useful for protecting admin areas, development sites, staging environments, or private files.

Using cPanel Directory Privacy

  1. Log in to cPanel
  2. Go to Files → Directory Privacy
  3. Navigate to the folder you want to protect
  4. Click the folder name (not the navigate icon)
  5. Check Password protect this directory
  6. Enter a name for the protected area (shown in the browser login dialog)
  7. Click Save
  8. Scroll down to create a username and password for access, then click Add/modify authorized user

The directory is now protected. Anyone who visits a URL inside that folder will see a login dialog. You can add multiple authorized users.

Protect a staging WordPress site

If you have a WordPress staging site at a subdirectory (e.g., yourdomain.com/staging/), password protecting that directory prevents search engines and the public from indexing the duplicate content.

Remove password protection

  1. Go back to Directory Privacy
  2. Click the protected folder
  3. Uncheck Password protect this directory
  4. Click Save

Manual method via .htaccess

For more control, add the following to a .htaccess file inside the directory you want to protect:

AuthType Basic
AuthName "Protected Area"
AuthUserFile /home/cpusername/.htpasswd
Require valid-user

Then create the .htpasswd file outside public_html (so it cannot be downloaded). Generate the password hash at htpasswd.net and paste the result into the file.

Related: htaccess guide | Shared hosting overview | Upload website | Resource limits

Was this article helpful?

Need shared hosting?

Choose an UnderHost shared hosting plan with cPanel, email, SSL, DNS tools, and 24/7 support.

Related articles

Back to Shared Hosting