How to Password Protect Directories in cPanel

 

 

Normally, if you create a folder on your site, you can access all the files inside it just by visiting the file’s URL. Sometimes however, you want to password protect directories in cPanel – either you’re testing a new design that you’re not ready to show the world, or it’s a staging area for your site. Or maybe you just want to prevent unauthorized access to sensitive parts your site. Like the “wp-admin” area of WordPress for example.

Whatever the reason, this tutorial will show you how to achieve this. First, I’ll create a test folder and file on my site via FTP:

Password Protect Directories in cPanel

As you can see, I can view this file simply by typing in the URL as shown below:

how-to-use-cpanel-to-protect-directories-with-a-password-2435940

Now we’ll see how to protect this folder with a password.

Step 1: Log into cPanel and Choose the “Password Protect” Icon

Logging into cPanel is easy. Use either:

https://[yourdomainname]:2083
or
https://[yourdomainname]/cpanel

Type in the login credentials for your site and scroll down till you reach the “Security” section and click on the icon labelled “Password Protect Directories” as shown here:
how-to-add-password-protection-for-a-directory-using-cpanel-7547047

Step 2: Choose the Folder to Password Protect

This will bring up a dialogue box asking if you want to open your root folder, or the folder of one of your sites.
How To Password Protect a Directory in cPanel

In our example, We’ve placed the directory in the root folder so we choose the first option. But if you’ve created a new site to which you want to restrict access, then it’s easier to go directly to the folder. Whatever you choose, the next screen will show you a list of folders in your selected directory like this:
how-to-password-protect-files-and-directories-with-cpanel-7587850

Find the folder you want to protect and click it.

Step 3: Give the Folder a Name

In the next screen, tick the box labelled “Password protect this directory”. Also, give the folder a name that is distinct from the actual folder name:
password-protect-directories-with-cpanel-1297840
Now click the “Save” button. This will lead you to a new screen telling you that the access permissions for the folder have been saved. Hit “Go Back” and you’ll be sent back to the previous screen. The folder is now inaccessible from the public web. Right now however, no one can view the files inside it! We need to create a username and password to allow people through.

Step 4: Create Usernames and Passwords

Now under “Create User”, enter a username and password which will be used to access the folder and its contents:
cpanel-protect-a-directory-with-password-5032641
In the image above, I haven’t created a very strong password because this is just for demo purposes. In practice however, make sure that the strength bar is “green”. Even better, click the “Password Generator” button which will create a strong password for you. Once you’ve copied and pasted the password into both fields, click the button “Add or Modify The Authorized User”.
This will bring up a notification that the user has been created. It’ll also show you the username and password in plain text on the screen so you can confirm it (It’s another matter whether or not passwords should be shown on the screen in plain text!).

If you click “Go Back”, you’ll see a new section called “Authorized Users:
password-protect-directories-cpanel-7078029

You can create multiple username/password pairs. This might be useful to give someone temporary access to your site. Once their work is done, you can just delete their username from the authorized users list and you’re protected again!

If you open the list of folders, this time you’ll see a “lock” icon next to the directory we just protected with a password:
password-protect-directories-using-cpanel-8170310

Step 5: Testing to See if it Works

Now that our folder is password protected, let’s navigate to the file again and see what happens:
how-to-protect-files-and-folders-in-cpanel-9679882

As you can see, it now shows me a pop up asking for my login credentials. We’ve successfully protected our folder with a password from cPanel!

Original Article