Password protect a folder on your website
Password protecting a folder makes visitors identify themselves before they open that folder's pages. cPanel does it for you: it writes the .htaccess and .htpasswd files on your behalf.
Before you start
- Have your cPanel credentials ready: see Log in to cPanel.
- Pick the folder to protect, for example
public_html/private. If you protect the site's root folder (public_html), the whole site asks for a password. - This is not complete protection: cPanel states that it only covers access to the folder through the website (the browser). It does not protect access through FTP, SFTP, Web Disk or other services, nor local access to the files. Backups and FTP accounts have their own passwords.
- Directory Privacy only appears if your hosting provider has enabled it for your account.
- The labels below come from cPanel's official documentation, in English; the French version of your cPanel may translate some of them.
Steps
Protect the folder
- In cPanel, open Files › Directory Privacy.
- In the list, click a folder's name to open it, then a subfolder's name to go down. When you reach the right folder, click Edit in the Actions column.
- Tick Password protect this directory.
- Enter a name in Enter a name for the protected directory. According to cPanel, this name is only a label for the folder in its
.htaccessfile: do not confuse it with the folder's real name. - Click Save, then Go Back.
At this point nobody has an account to get in: create a user now.
Create an authorized user
- In the Create User area, enter the Username.
- Enter the password and its confirmation. cPanel rates its strength out of 100; Password Generator suggests a strong one.
- Click Save, then Go Back.
These credentials belong to the folder: they are separate from cPanel's and from your email addresses'. To change an existing user's password, enter their username and the new password, then click Save.
Remove a user or the protection
- Delete a user: in the Authorized Users menu, select them, then click Delete User.
- Remove the protection: untick Password protect this directory, then click Save.
Expected result
When you open the folder's address in the browser (for example https://your-domain.com/private/), a window asks for a username and password. With the credentials you created, the content shows; otherwise access is refused. The lock icon in the Directory Privacy list marks folders that are already protected. A protected folder's subfolders inherit its protection.
If something goes wrong
- You cannot create the user: the folder does not have the right permissions. cPanel says to set its permissions to
0700in the File Manager (select the folder, Permissions, Change Permissions), then try again. - The window does not show: clear your browser cache or try a private window. Check that you clicked Save after ticking the protection, and that a user exists.
- The credentials are refused: do Save again with a new password for the user.
- A file in the folder is still reachable over FTP or SFTP: that is normal, the protection does not apply to those accesses.
FAQ
What does cPanel change on my site?
It adds directives to the folder's .htaccess file and creates an .htpasswd file for the users. You do not need to edit them by hand.
Can I protect a development site or a private area?
Yes, that is a common use: protect the test site's folder or the restricted area. For a whole site, protect its root folder.
Is it enough for confidential data?
No. A password on a folder limits access through a browser, but does not encrypt the files and does not protect their transfer over FTP. Always use an encrypted connection (an https address) so the username does not travel in clear, and do not put sensitive data in a public folder.
Can I also block certain IP addresses?
Yes, with the IP Blocker screen: see Block an IP address on your website. It denies access to specific addresses; it does not replace a password.
Related articles
- Block an IP address on your website (cPanel)
- Use cPanel's File Manager
- Log in to cPanel: address, credentials and a tour of the interface
- Create additional FTP accounts in cPanel
A site to secure? Discover our security solutions.