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.
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
- Log in to cPanel
- Go to Files → Directory Privacy
- Navigate to the folder you want to protect
- Click the folder name (not the navigate icon)
- Check Password protect this directory
- Enter a name for the protected area (shown in the browser login dialog)
- Click Save
- 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.
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
- Go back to Directory Privacy
- Click the protected folder
- Uncheck Password protect this directory
- 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
Need shared hosting?
Choose an UnderHost shared hosting plan with cPanel, email, SSL, DNS tools, and 24/7 support.





















