
|
 |
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 you want to password protect in your
www
(example: members)
- Create a file
.htaccess in that directory that looks
like:
AuthUserFile /usr/sites/username/.htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic
<Limit GET>
require user myfriend
</Limit>
Important! Replace AuthUserFile path with REAL path to
your login directory!
- Create the password file in your login directory using the
program
htpasswd To do this, log into your account via
SSH and type:
/usr/local/apache/bin/htpasswd -c .htpasswd myfriend
- When prompted, enter the password for that user.
- Now try to access a file in the protected directory by entering the
set username and password when prompted for it.
Multiple User/Group Protection:
- Create your directory in
www (example: members),
to contain the protected files.
- Create a file
.htgroup in your login directory
that contains the group name and list of users:
members: user1 user2 user3
- Modify
.htaccess, so it looks like:
AuthUserFile /usr/sites/username/.htpasswd
AuthGroupFile /usr/sites/username/.htgroup
AuthName ByPassword
AuthType Basic
<Limit GET>
require group members
</Limit>
Important! Replace AuthUserFile path with REAL path to
your login directory!
- 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 the file .htpasswd already exists
(-c is used to create a new file).
/usr/local/apache/bin/htpasswd .htpasswd user1
/usr/local/apache/bin/htpasswd .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.
Keep in mind that: 1. all files should have a blank line at the bottom
and 2. always use the full path to your configuration files.
For further details, please refer to the Apache
mod_auth docs
|