Control access to directories and files by using password protection on directories using cPanel
There will come a time when you want to allow only certain persons to view files within certain directories in your web site, this can be easily achieved by placing password protection on such directories so that any visitor must provide a valid username and password to view any of the files therein. You can add as many users as you wish for each directory and cPanel offers an intuitive interface for adding this password protection.
When a visitor navigates to a password protected directory wet up using this utility, they will see a pop-up username and password prompt which must be completed with a user name and password that you have added during the password protect process detailed below and in the video tutorial.
You must first log into your cPanel hosting control panel.
Once logged in, we will proceed with adding password protection to a directory in your cPanel.
cPanel Directory Password Protection video tutorial...
First, click on the Password Protect Directories icon in the Preferences section
Adding Password Protection to a Directory
We will now be faced with a 'po-up' type window which requires us to provide details of the directory we wish to place password protection on.
The first two check boxes ask for us to select the path to the directory, if it is a directory in your main domain (i.e. in your root web folder - public_html) then we must check the first box titled Web Root (public_html/www). We use the second check box titled Document Root for: to select a domain that you have added to your web hosting account.
Using the video tutorial example above, we will select the Document Root for: check box, then we'll select the domain from the following drop down list (in this example we select mycpaneldemos.com.
The following two check boxes are optional. The first one titled Show Hidden Files (dotfiles) will allow users to see files which are normally hidden from view (such as .htaccess files). We don't recommend that you select this box unless you have a specific need to show these kinds of files). The second check box titled Skip this question, and always open this directory in the future when opening Password Protect Directories will skip this pop-up window the next time you use the Password Protect Directories link in cPanel. We leave both of these check boxes unchecked in the video tutorial above.
Now click the Go button to add password protection to one of the directories in the folder or location that we have selected.
We are now faced with the Password Protect Directories page where we will select the directory that we wish to restrict access to with password protection.
You configure password protection for a folder by clicking on the folder name in the list and you can navigate to and select a sub directory by clicking on the folder icon next to the top level directory name. For example let's say that you wanted to password protect a directory called securefolder and it was a sub folder of mainfolder - simply click on the folder icon immediately to the right of the folder named mainfolder in the list, this will then list all sub directories under that folder. Then simply click on the folder named securefolder to configure password protection.
Following the video tutorial above, in this instance we click on the folder icon to the right of public_html and the next page then lists all folders in public_html. And now, as in the video tutorial, we select the folder named images by clicking on the folder name.
We now come to the page on which we will set permissions, add users and manage users who will be allowed to access this folder when they provide the correct user names and passwords which will will also add here.
Configuring directory password protection
We are obviously at this page because we want to protect the selected directory with passwords, so in the section titled Security Settings we must tick the first check box titled Password protect this directory. Now move to the Name the protected directory entry box and provide a name for the password protected directory (this will be displayed in the pop-up log in prompt that users will see when viewing this folder with their browser), using the video tutorial as an example we enter the name as image. Now Click the Save button. A confirmation page follows, so click the Go Back link when you are ready.
Now we must add one or more users and set their passwords, of-course users can all use the same username and password but you may wish to add additional users which you can do at any time.
Scroll down to the section titled Create User and in the entry box titled Username provide the username that your visitor(s) will use to access the directory contents. Then provide the password in the entry boxes titled Password and Password (Again). Pay attention to the password strength meter and always attempt to achieve a Very Strong result. Now click the Add/modify authorized user button to add the username and password. A confirmation page follows which details the username and password you have just added. Click the Go back link to add more users if you wish. You will also be able to remove users and you can change a user's password by adding the user again using the new password.