Ahosting Logo
Knowledge Base

How to Password Protect Directories in cPanel

Password protecting a directory adds an extra layer of security. Visitors must enter a username and password to access the protected folder.

Common Use Cases

  • Protect admin areas
  • Secure staging/development sites
  • Restrict access to private files
  • Create members-only sections
  • Protect wp-admin for extra WordPress security

Method 1: Directory Privacy Tool

  1. Log into cPanel
  2. Go to Files section
  3. Click Directory Privacy
  4. Navigate to the folder you want to protect
  5. Click the folder name
  6. Check Password protect this directory
  7. Enter a name for the protected area (shown in login prompt)
  8. Click Save
  9. Create a user:
    • Enter username
    • Enter and confirm password
    • Click Save

Method 2: Manual .htaccess

For more control, create files manually:

Step 1: Create .htpasswd file

Store this OUTSIDE public_html for security:

  1. Go to File Manager
  2. Navigate to your home directory (above public_html)
  3. Create a new file called .htpasswd
  4. Add encrypted password entries

Generate password hash at: htpasswdgenerator.net

Format:

username:$apr1$encrypted$passwordhash

Step 2: Create .htaccess in protected folder

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/.htpasswd
Require valid-user

Protecting WordPress wp-admin

  1. Go to Directory Privacy
  2. Navigate to public_html/wp-admin
  3. Enable password protection
  4. Create a user

Note: You may need to allow admin-ajax.php for some plugins:

Add to wp-admin/.htaccess:

<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>

Adding Multiple Users

  1. Go to Directory Privacy
  2. Click the protected folder
  3. Under Create User, add another user
  4. Each user can have a different password

Removing Password Protection

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

Removing a User

  1. Go to Directory Privacy
  2. Click the protected folder
  3. Find the user under Authorized Users
  4. Click Delete next to their name

Troubleshooting

  • 500 Error: Check .htaccess syntax and file paths
  • Password not accepted: Ensure password was saved correctly, try recreating user
  • Redirect loop: Check for conflicting .htaccess rules