Security and SSL
Protect a directory with a username and password in cPanel
Directory Privacy adds a username and password prompt to web access to a folder. It can be used for a website under development or a restricted area, but it does not replace the application's users and permissions.
The protection does not apply on its own to FTP, SFTP or processes that access the files locally. Use HTTPS so that the password does not travel over an unencrypted connection.
Enable the protection and create a user
- Open cPanel > Directory Privacy and find the correct folder. Check the domain's document root if you have several websites.
- Open its options with Edit or the control your version of the panel shows.
- Enable Password protect this directory, enter a label to identify it and save. The label does not rename the folder.
- Go back to the same screen and create an authorised user with a unique password. Enabling the protection does not create that user automatically.
- Open the URL over HTTPS from a private window and check that it asks for credentials, rejects incorrect ones and accepts the ones you created.
Review the paths that depend on that folder
Subdirectories may inherit the protection. Also test direct links to files and features such as forms, AJAX and webhooks. Protecting the whole document root can stop an automated integration from reaching its endpoint.
If you need an exception, see how to allow a specific file. Do not open up an entire administrative directory to fix a single call.
Change or remove access
Manage authorised users from the same tool and delete those who should no longer have access. To remove the folder's protection, untick the option and save; then check that the result is what you expected.
A password remembered by the browser can hide the login prompt. Use a new private session to check the changes, and keep a way to manage the hosting in case a rule stops the website from opening.
You may also find useful
- Change the main cPanel, FTP and SSH password Change the hosting's main credential and check which connections need updating afterwards.
- Enable two-step verification in the client area Set up a TOTP app to protect your login and prepare for changing phone without losing your second fa...
- Exclude a directory or file when protecting a directory with a username and password Shows how to exclude a specific file from basic authentication with a Require rule in .htaccess with...
- How passwords are stolen and what to check if it happens Recognise phishing, password reuse and compromised devices, and regain control of the affected crede...
Something wrong or out of date? Tell us and we will review it.