The Directory Privacy page lets you password-protect a directory. You can use this option to give specific users access to a part of your website. The user will need to enter their username and password to access the page.

Creating a password-protected folder is not very difficult but the process is not very intuitive. Let’s look at an example…

Selecting a directory

On the Directory Privacy page you see the same directories we saw when we looked at cPanel’s file manager.

  • You can navigate to the directory you want to protect by clicking on the folder-icons
  • To select the directory you can click on its name

Note: if you want to password-protect your entire website then you can simply click on the public_html link.

In the below example we have navigated to the public_html directory. Inside the directory is a folder called private-files. This is the folder that we are going to protect. To do so, simply click on the name:

Selecting the directory we want to protect.
Image: selecting the ‘private-files’ directory

Protecting a directory is a two-step process:

  • We need to tick the Password-protect this directory checkbox
  • We need to enter a name for the protected directory. This name will be shown when someone tries to access the directory (as will see in just a moment).

Creating a user

At this point we have password-protected the directory. However, we haven’t yet created a user name and password for the directory. As things stand nobody is able to access the directory.

The next step is therefore creating a user that is allowed to access the directory. In the below example we are creating the user Fruitcake:

Creating a user for the password-protected directory.
Image: creating a user that may access the directory.

And that’s it, anyone who now tries to access will be prompted for a user name and password. If they get the user name or password wrong they will see an error 401 (“Access Denied”).

An 'Authentication Required' dialogue window.
Image: The password prompt.

As you can see in the above image, the name we entered for the directory (“Private files”) is shown in the dialogue window. You can use the name to give the user a hint. For instance, instead of “Private files” we could have named the directory “your favourite lunch”. In that case your browser would show the message: ‘The site says: “your favourite lunch”.

Managing user accounts

You can create more than one authorised user. Users you add will be listed at the bottom of the page, with the option to delete the user.

Removing password protection

Removing the password protection is again a two-step process:

  • Navigate to the directory
  • Untick the Password-protect this directory checkbox