htpassword protected directory

Any sensitive directory inside the linux server have to be password protected or the sensitive datas might get lost. The most secure way of protecting a web folder is to use htaccess and htpassword.

If you are a beginner, we recommend using the cPanel Password Protect Directory icon. That icon can only protect all the files in a folder, not one specific file.

  • Create a file named .htpasswd and place it above your web folder so visitors can’t access it.
    EXAMPLE: /home/$user/public_html/web/.htpasswd
  • Put the username and encrypted password inside the .htpasswd file. EXAMPLE:

Place the below shown codes in the .htaccess file which is in the folder '/home/$user/public_html/web/'

<FilesMatch "file.html">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/$user/public_html/web/.htpasswd
require valid-user

create the new user, here in this example(newuser) with the command htpasswd like shown below.

htpasswd -c /home/$user/public_html/web/.htpasswd  newuser

then the command prompt will ask for the password for the user to be entered.


There are no revisions for this post.

Tags: , , , ,

No comments yet.

Leave a Reply