You
can password protect directories of your web site, so only users
with a given username and password can access that directory and
files within it. The most popular method used is HTAccess, as described
below.
Single
User Protection:
Create
the directory your want to password protect in your public_html
(example: membersonly)
Create
a file .htaccess in that directory that looks similar to:
Create
the password file (.htpasswd) using the program htpasswd for
each user (as above in part 1) You don't need the -c option if
you are using the same .htpasswd file (-c is used to create a
new file).
htpasswd /homeX/domain/.htpasswd user1
htpasswd /homeX/domain/.htpasswd user2
and so on...
Remember
to add any new users to the .htgroup file.
Now
try to access a file in the protected directory by entering the
set username and password when prompted for it.
If
you add additional users, make sure to use htpasswd without the
-c flag, which is used to create a new file.
Keep
in mind that all files should have a blank line at the bottom and
to always use the full path to your configuration files.
If you will have more than a hundred users, we recommend that you use
DBM-based authentification, to speed up user login process.
DBM Authentification Set-Up:
1. create your password-protected directory inside public_html (eg.
cd public_html ; mkdir directory).
2. create the directory where the password files will be stored inside
your ROOT directory (NOT public_html for security purposes; eg. cd ~ ;
mkdir access).
3. in the protected (in public_html) directory, create an .htaccess
file.
Example:
4. In the access (not in public_html) directory, do
ln -s .htpasswd .htpasswd.pag
and then
ln -s .htpasswd .htpasswd.dir
5. Then use dbmm program (/usr/local/bin/dbmm).
to add users, use the command:
dbmm /home3/yourdomain/access/.htpasswd adduser username password
for more details, run dbmm without any arguments and it will give you
the further usage details.
If you would like to use group-based access control as well (the above
is plain user based, though you can add as many users as you wish), please
follow the further Apache
instructions (create a group db file, or combine then as in the instructions
there).
Keep in mind that all files should have a blank line at the bottom and
to always use the full path to your config files.
where yourdomain.com is your domain and authorizedlinksite.com is a site
that can link to your restricted directory. There can be no, or multiple,
such authorized link sites. Note that the trailing slashes (/) are important
and must be included.
3. Now try to access the authorized directory from a link on your site,
from a link on the authorized site(s), if any, and, if possible, from
a link from an unauthorized site (to ensure that it is restricting access
properly). The latter test can be conducted using a link from a sub-directory
of your site (eg. http://www.yourdomain.com/somedirectory/) that is not
listed as a valid referrer as well.