Knowledge Base
MilesWeb / How-Tos

How to Protect a Directory with a Password?

Approx. read time : 3 min

Watch this video for a step by step process on how to protect a directory with a password

Directories can be password protected via cPanel. This secures all the files within the password-protected folders.

Note: The cPanel can only protect directories and not individual files. Any file that needs to be protected can be located in a protected directory. Moreover, it does not protect the directories that are accessible locally or through FTP, SFTP, or Web Disk.

Steps to Protect a Directory with the help of a Password

1. Login to your cPanel account.

2. Navigate to the Files section and click on Directory Privacy.

3. Click on the directory that you want to protect.

4. You will be redirected to a page “Set permissions for “/home/idigitalcamp/public_html”.

5. Tick the option Password protect this directory as in the above screenshot.

6. Under Security Settings type the name for the selected directory in the Enter a name for the protected directory field. Note that this is the label of that directory. It doesn’t change the actual name of the directory.

7. Next, click on the Save button.

8. A confirmation page will get displayed. Here, click on Go Back.

9. Then you need to create a user that can access this directory. For this under Create User, fill in the Username, New Password, and Confirm Password fields. The Password Generator button will help you to generate a strong password.

10. Then click the Save button.

11. Lastly, click on Go Back.

12. To check if your directory has been password protected, go to your browser and browse the directory. If the browser asks you to log in, then your folder has been password protected. In this example, the public_html (the domain name, example.com) has been accessed in a browser. When anyone accesses it, a pop-up box will get displayed as below:

Note: Enter the username and password created in the previous step to access the directory.

Getting a 404 Error When Browsing a URL With a Shared Server SSL

Suppose you are accessing a password-protected directory with a URL containing the use of a shared server SSL (https://securexxx.milesweb.com/~/) and getting a 404 error, it is because Apache is searching for a 401 page and displaying a 404 when it is not found.

The solution to this error is to add a single line to the .htaccess file in the protected directory, so that Apache gets the 401 pages it is looking for (ErrorDocument 401 Authorization Required).

Example

In the below code, ensure to replace yourusername with your actual cPanel username, and also ensure the example123 is replaced with your actual server number. You will get this information in your Welcome Email as well as on the left navigation menu in your cPanel.

Before Fix:

[root@example123 /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@example123 /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"

Getting 500 Error After Login

Check the ownership on the .htpasswds folder (above public_html). Change it from user.user to user.nobody and check if the permissions are set to 750 and then refresh your protected page. The error will be resolved.

In this way, you can easily protect a directory with a password.

 

Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna