Password protecting directories is useful in cases where you wish to grant specific users access to specific directories while denying any attempts to access such directories for anyone else. In this example, you will see how to password a directory that contains a few documents we want to keep private, but accessible through our website if a user has the correct login credentials.
What you’ll need
Before you begin this guide you’ll need the following:
- Access to the cPanel of your hosting account
- A folder you wish to protect
Table of Contents
Step 1 — Logging into your cPanel
Login into the cPanel of your hosting account and find the “Directory Privacy” tool. It can also be named “Password protection” or similar.
Once inside, use the small icon to navigate the directory tree. Click the one next to ‘public_html’ to delve deeper into that folder.
Step 3 — Selecting the directory to be protected
Once you have found the directory that you want to protect, click on the name of the directory to open cPanel’s Security Manager of that directory. In this example, we will be protecting the
Step 4 — Enabling password protection
In order to enable password protection for your directory, check the Password protect this directory option and input a label for your directory, i.e. “Archived documents 2016”. Click Save to enable password protection for that directory.
Step 5 — Creating a user to access the directory.
IMPORTANT! Our directory is now protected, however, there are no users created that can access it. You must create a user that can access this directory. This must be done on the same page, simply find the Create User section and input the username and password and click Save to create your user. Make sure to use a strong password for your user.
Step 6 — Testing our password protection
All that remains is to try and access our directory. In our example, we will visit http://domainname.com/archives2016/. We are prompted with a username and password prompt. Let’s input our user credentials that we created in the last step and try to access the directory.
Success! We successfully logged in with the username and password that we created. If an incorrect username or password is supplied, access to the directory will be denied.
- To change a user’s password, enter the user’s information again in the Create User section of the interface, but enter a different password for the user and click Save.
- To remove password protection from the directory, deselect the Password protect this directory checkbox in the Security Settings section of the interface and click Save.
We learned how to password protect directories via cPanel’s Directory Privacy tool. Additional information is available at https://documentation.cpanel.net/display/ALD/Directory+Privacy