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
- Log into cPanel
- Go to Files section
- Click Directory Privacy
- Navigate to the folder you want to protect
- Click the folder name
- Check Password protect this directory
- Enter a name for the protected area (shown in login prompt)
- Click Save
- 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:
- Go to File Manager
- Navigate to your home directory (above public_html)
- Create a new file called
.htpasswd - 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
- Go to Directory Privacy
- Navigate to
public_html/wp-admin - Enable password protection
- 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
- Go to Directory Privacy
- Click the protected folder
- Under Create User, add another user
- Each user can have a different password
Removing Password Protection
- Go to Directory Privacy
- Click the protected folder
- Uncheck Password protect this directory
- Click Save
Removing a User
- Go to Directory Privacy
- Click the protected folder
- Find the user under Authorized Users
- 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