How to Password Protect a Directory in cPanel
You can restrict access to any folder on your hosting account so that visitors must enter a username and password before viewing its contents. This is useful for protecting admin areas, staging sites, private files, or members-only sections.
Steps to Set Up Password Protection
- Log into your cPanel hosting control panel
- In the Files section, click Directory Privacy
- Navigate to and select the folder you want to protect
- Check the box for Password protect this directory
- Enter a name for the protected directory (this will appear in the login prompt visitors see)
- Click Save
- On the next screen, create a username and password for access
Once configured, anyone who visits that directory in their browser will be prompted with a login dialog box before the page loads.
What Happens Behind the Scenes
When you password protect a directory, cPanel creates a .htaccess file and a .htpasswd file for that directory. The .htaccess file tells the server to require authentication, and the .htpasswd file stores the encrypted credentials. You can also set this up manually via .htaccess if you prefer more control over the configuration.
Adding Multiple Users
You can create multiple usernames for the same protected directory. Each user will have their own login credentials. Go back to the Directory Privacy settings for that folder and add additional users as needed.
