Skip to main content

Password Protecting a Directory

files, htaccess, password, security 0 Was this answer helpful?

You can add password protection to any directory on your website. Visitors will be prompted for a username and password before they can view any files in that directory. This is useful for staging areas, admin sections, or private content.

Please note: Screens and options may vary slightly depending on your cPanel version and hosting plan.

When You Would Use This

Use this for staging areas, admin sections, client-only content, or any directory you want to restrict access to.

Setting Up Directory Privacy

  1. Log in to your cPanel account.
  2. In the Files section, click Directory Privacy.
  3. Navigate through the directory tree and click on the folder you want to protect.
  4. Tick Password protect this directory.
  5. Enter a name for the protected directory (this appears in the login prompt).
  6. Click Save.
  7. Under Create User, enter a Username and Password.
  8. Click Add/Modify Authorised User.

You can add multiple users with different credentials to the same protected directory.

How It Works

Directory privacy uses Apache's HTTP Basic Authentication. When enabled, cPanel creates two files:

  • .htaccess — In the protected directory, containing the authentication directives.
  • .htpasswd — In a secure location outside public_html, containing the encrypted usernames and passwords.

Removing Password Protection

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

To remove individual users, delete them from the user list on the same page.

Tips

  • Directory privacy uses HTTP Basic Authentication, which sends credentials in base64 encoding. Always use HTTPS (SSL) on password-protected directories to encrypt the transmission.
  • This feature is separate from your website's own login system (e.g. WordPress login). Both can be used together for additional security.
  • You can manually edit the .htaccess and .htpasswd files for more advanced configurations, but it's generally easier to use the cPanel interface.

What Next?

Related Articles

knowledgebasedidyoufindanswer