مرکز آموزش

How to Protect a Directory with a Password

You can password protect directories (folders) via the cPanel, protecting all the files within the password-protected folders.

Note: At this time, the cPanel can only protect directories, not individual files. Any file that needs protection can be placed in a protected directory. This also does not protect the directories that can be accessed locally or through FTP, SFTP, or Web Disk.

To password-protect a directory:

1. Log in to your cPanel.

2. Look for the Files section, then click on the Directory Privacy icon.

HostGator - cPanel - Directory Privacy

3. Locate the name of the directory you wish to password protect.

HostGator - cPanel - Directory Privacy - Choose Directory

4. Click on your directory's Edit button.

5. Put a checkmark on Password protect this directory.

HostGator - cPanel - Directory Privacy - Enter a Name

6. Enter a name for the selected directory. It is important to note that this serves as the label of that directory. It does not change the directory's actual name.

cPanel - Directory Privacy - Enter Name

7. Click on the Save button.

8. A confirmation page will appear. Click Go Back

HostGator - cPanel - Directory Privacy - Confirmation Prompt

9. You will then need to create a User that can have access to this directory.

10. Fill in the Username, New Password, and Confirm Password boxes. You can utilize the Password Generator button to generate a strong password.

HostGator - cPanel - Create User - Fill out Information

11. Click the Save button.

How To Check if Directory Has Been Password Protected?

To ensure your directory has been password protected, launch your browser and view the directory.

If the browser prompts you to log in, then your folder has been password protected. This example shows the public_html (the domain name, example.com) has been accessed in a browser. When accessed, a pop-up box will show up.

Password Protect URL in Browser

You can enter the user and password you created earlier to access the directory.

404 Error When Using a URL With a Shared Server SSL

If you are accessing a password-protected directory with a URL that includes the use of a shared server SSL (https://securexxx.WalexBiz Host.com/~<user>/<whatever>) and receiving a 404 error, this is because Apache is looking for a 401 page and serving a 404 when it is not found.

To resolve this, add a single line to the .htaccess file in the protected directory to give Apache the 401 pages it is looking for (ErrorDocument 401 Authorization Required).

Example

In the following code, please be sure to replace yourusername with your actual cPanel username, and also be sure the gator123 is replaced with your actual server number. This information can be found in your Welcome Email as well as on the left navigation menu in your cPanel.

Before Fix:

[root@gator123 /home/yourusername/www/home]# more .htaccess.old
 
AuthType Basic
AuthName "home"
AuthUserFile "/home/yourusername/.htpasswds/public_html/home/passwd"
require valid-user 

After Fix:

[root@gator123 /home/yourusername/www/home]# more .htaccess
 
AuthType Basic
AuthName "home"
AuthUserFile "/home/yourusername/.htpasswds/public_html/home/passwd"
require valid-user
ErrorDocument 401 "Authorization Required"

500 Error After Login

Check the folder ownership on the .htpasswds folder (above public_html). Change them from user.user to user.nobody and ensure the permissions are set to 750, and then refresh your protected page. The error will be gone.

Shared and Reseller customers will need WalexBiz Host's help to change any file's ownership. Please contact us via via our phone line +234 901 729 2738 or Live Chat to make this change.
 
  • Password, cPanel
  • 0 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟