How to Set a Password for a Folder in cPanel
Sometimes, it is necessary to set security measures on a specific folder so that only certain users have access to it. This article explains how to set a password for a specific folder or directory in cPanel so that only those with the password can access it.
It is important to note that when you set a password on a folder, all its contents are protected.
As shown in the image below, first log in to cPanel and open the Directory Privacy section.
In the Current Directory section, find the folder you want and click Edit:
In the Security Setting section, check the option “Password protect this directory” and save it.
On the new page that opens, you need to set the desired username and password:
After that, if you access the link to the desired directory, you will be asked for a username and password. In this article, the password is set for the main folder, i.e., public_html, so when you open the website, you will be prompted for a username and password.
To disable it, you can go back to the Directory Privacy section, click Edit, and uncheck the option “Password protect this directory” to disable it.
It is important to note that these changes are also saved in the .htaccess file. The following parameters are automatically added to the .htaccess file:
AuthType Basic
AuthName “Protected ‘public_html'”
AuthUserFile “/home/dlserver/.htpasswds/public_html/passwd”
Require valid-user
Therefore, if you delete the .htaccess file or change its content, these settings will be removed.