5. What about restricting access by username/password?
It is also possible to protect Web directories by username/password combinations. In order to set this up you should follow these steps if you using the OUCS web server (if you are using a different server contact that system's sysadmin):
- Log in to the Linux system
linux.ox.ac.ukusing your Oxford username and password - Create a file containing usernames and encrypted passwords:
% htpasswd [-c] passwordfile username% htpasswd -c /web/users/$USER/cgi/myusers.passwd fred Adding user fred New password: rubbish (not echoed) Re-type new password: rubbish (not echoed)
The file used to store the passwords should not be in the accessible document tree; the cgi directory is a good location (on
linux.ox.ac.ukthis can be accessed as/web/users/$USER/cgi).The -c flag is only needed the first time that the command is used.
You will be prompted twice for each user's password. You will need to use the
htpasswdcommand for each user you want to add. - Make sure that the file which holds the passwords is
world-readable. For example:
% chmod a+r /web/users/$USER/cgi/myusers.passwd
-
The commands to activate the password file are placed in the
.htaccessfile. As before, this file needs to be placed in the directory where access restriction is to start. For example:AuthType Basic AuthName my-private-webpages AuthUserFile /web/users/aragog.oucs.ox.ac.uk/6/e/fred/cgi/myusers.passwd require valid-user
AuthName can be anything meaningful to the people that need to supply a username and password (note that a value is required). If the name contains spaces, it must be given in quotes. Using the above example, when the username is requested the browser will display "Please enter username for my-private-webpages at users.ox.ac.uk" - Make sure that
.htaccesshas got world read access:% chmod a+r .htaccess - If you want to authenticate by both username/password and
client host address, you can use the Satisfy directive in
.htaccessto specify whether access is allowed if either test is passed, or if both must be passed (the default).
Up: Contents Previous: 4. How do you restrict access to web pages? Next: 6. Making a custom error page and redirect

