The web document to be protected. Actually, access is restricted by directory so all files in the same directory will be protected.
The file .htaccess. This file should be in the directory which contains the documents to restrict access to. The contents of this file specify the name of the password file.For example if you were user jdoe with web documents in the local directory “/home/jdoe/public_html/goodstuff” that you wanted to restrict access to, your .htaccess might look like:
AuthUserFile /home/jdoe/public_html/goodstuff/.htpasswd
AuthName jdoe_goodstuff
AuthType Basic
<Limit GET>
require valid-user
</Limit>
Note that .htaccess will not work if there are extra spaces after AuthUserFile.
The file .htpasswd. This file contains the passwords of the users.To create the .htpasswd file log in to this server using SSH, change directory to the directory you want to restrict access to, and type:
htpasswd -c .htpasswd someuser
for the first user (where someuser is the username). You will then be prompted twice for the user’s password. The -c option causes the .htpasswd file to be created. For each additional user type:
htpasswd .htpasswd someuser
NOTE: There is no correspondence between the usernames and passwords used for accounts on this server and usernames and passwords in any specific .htpasswd file. A user doesn’t need to have an account on this system in order to be validated for access to files protected by HTTP-based authentication.
Courtesy: he.net
0 Responses.