How to Password Protect a Directory in cPanel


Password protecting a directory adds an extra layer of security by requiring a username and password before anyone can access files in that folder. This is useful for protecting admin areas, staging websites, or private content.

Steps to Password Protect a Directory

  1. Login to cPanel.
  2. Under the Files section, click Directory Privacy.
  3. Browse the directory tree and navigate to the folder you want to protect.
  4. Click the Edit icon (pencil) next to the folder.
  5. Check the box: Password protect this directory.
  6. Enter a Label for the protected area (shown on the login prompt).
  7. Click Save.

Adding an Authorized User

  1. After saving, scroll down to Create User.
  2. Enter a Username and Password.
  3. Click Save.

Anyone trying to access that directory will now see a browser login prompt. Only users with the correct credentials can access it.

Manual Setup via .htaccess

You can also password protect a directory manually:

# .htaccess file in the directory
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/.htpasswds/public_html/dirname/passwd
Require valid-user

Note: The AuthUserFile path must point to a valid .htpasswd file containing encrypted usernames and passwords. cPanel's Directory Privacy tool handles this automatically.

Removing Password Protection

To remove protection, go back to Directory Privacy, click Edit on the same folder, uncheck Password protect this directory, and click Save.

If you continue to face issues, please open a create a request.

¿Le ha resultado útil esta respuesta? 0 Los usuarios encontraron esto útil (0 Votos)