Lock a folder with .htaccess

To do this you have to create a username/password file, and a .htaccess

1)Inside the folder you want to lock (using ssh) run the command: htpasswd -c {.passfilename} {username} {pass} and press enter.

{.passfilename} = the filename in which login/pass will be stored , its better to put an “.” to make it hidden

{username} = the username you want to have.

{pass} = the password you want…

Then create an .htaccess file (for eg use vi: vi .htaccess) and fill it with the form:

AuthName “Authorization Required”
AuthType Basic
AuthUserFile {/path/.pass}
AuthGroupFile /dev/null
<Limit GET POST>
Require valid-user
</LIMIT>

in which you must replace {/path/.pass} with the path of your password file, for example: /home/httpd/vhosts/mydomain.com/httpdocs/.pass