Password protecting a directory on cPanel

Password protecting a directory restricts access to certain parts of your website by requiring visitors to enter a username and a password. This password process is also referred to as a type of “authentication” process.

cPanel Password Protect Directory icon.

(cPanel >> Security >> Password Protect Directories)

You can manually create password protect by using the following steps.

Create .htpasswd file for users and passwords:

htpasswd -c /path/to/file/.htpasswd username

This command will prompt you for the password.

Edit .htaccess:

AuthName “Members Only”
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
require valid-user
deny from all

You can protect more than one file by using wildcard names. On the FilesMatch line, follow one of these examples:
<FilesMatch “*.php”>
<FilesMatch “file.*”>
<FilesMatch “*.*”>

example

<FilesMatch “*.php”>
AuthName “Member Only”
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user
</FilesMatch>

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

cPHulk Brute Force Protection

WHM/cPanel has a service, protected from Brute Force attack, which is called “cPHulk Brute Force...

Enable SSH key authorized login without root password

You need to generate SSH Key ( the private key )on your cpanel server and then update remote...

How can I Redirect URLs in cPanel

Login your cpanel 1. Click the Redirects button on the front page under the “domains” 2. Enter...

Enable Custom php.ini for Fast CGI

With fast-cgi, custom php.ini needs to be in the cgi-bin folder. 1) Move php.ini to cgi-bin...

ConfigServer Firewall CSF installation

ConfigServer firewall is a popular linux firewall security suite. It is easy to install, flexible...

Powered by WHMCompleteSolution