htpasswd -c
passwordFile username
where username is the name of a user account which will have the right to gain access to the restricted web pages.
Example:
htpasswd -c courseUsers otto
Here the
passwordFile
is named as
courseUsers.
You will then be asked to enter a password for the user
otto
twice. (You should, of course, inform the user of
this username
and password for him to gain access to the restricted web pages.)
¡@
htpasswd
passwordFile anotherUserName
(Note: no "-c" flag after htpasswd.)
¡@
chmod 644 passwordFile
Example:
chmod 644 courseUsers
¡@
Example:
vi courseUsers
shows the following lines:
otto:38hi3sylap
billgate:v8302icd92
where otto
and billgate
are two authorized users'
names (their corresponding passwords are encrypted). You can delete either
one or both of the lines to remove the user(s) from the authorized user
list (i.e. the password file).
Create a file called .htaccess in the directory under which the files and its sub-directories are to be accessible only by the authorized users specified in the User Password file discussed above.
Example 1
Suppose the full path name of the passwordFile is /user3/otto/courseUsers and the full path name of the directory of the web page files which require access control is /user3/otto/dir1/.
The file
/user3/otto/dir1/.htaccess should be created and it should
contain:
AuthUserFile /user3/otto/courseUsers
AuthName HKU
AuthType Basic
require valid-user
Make sure that the full path of the passwordFile is specified in the .htaccess file.
Please note that the keywords AuthUserFile, AuthName, AuthType and require, and their assigned values must be on the same line. The value valid-user specifies all users in the password file.
Also, change the permission of the file .htaccess so that it can be read by others using the following command:
chmod 644 .htaccess
When a user views a web page file under the directory /user3/otto/dir1/, the web server will authenticate the user's access to the web page by means of his username and password in the password file /user3/otto/courseUsers.
Example 2
The file /user3/otto/dir2/.htaccess contains
AuthUserFile /user3/otto/courseUsers
AuthName HKU
AuthType Basic
require user apple otto
Please note that the keywords AuthUserFile, AuthName, AuthType and require, and their assigned values must be on the same line. The line "require user apple otto" specifies that only the user apple and otto can access the directory even the password file '/user3/otto/courseUseres' contains other users.
¡@