Example one:
Allow a user to access a directory
1. Use htpasswd to create user files:
$ htpasswd -c /data/httpd/secr/.htpasswd user
This program will ask for the password of user "user1". If you enter "passwd", it will take effect twice.
2. Create .htaccess file
Use the "vi /log/image/www/huodong/erge/admin/.htaccess" command to create the .htaccess file and write the following lines:
AuthName My Friend Only (Note: This name is optional)
AuthType Basic
AuthUserFile /data/httpd/secr/.htpasswd
require user user
Finally, set the file permissions of the files .htpasswd and .htaccess to ensure that the Apache user has read permissions. This completes the web page password setting.
3. Modify the httpd.conf file:
Use the "vi /data/httpd/conf/httpd.conf" file and add a few lines:
Options Indexes FollowSymLinks
AllowOverride authconfig
Order allow,deny
Allow from all
#
#AccessFileName .htpaccess
#AllowOverride ALL
#
Example two:
Allow a group of users to access a directory. Two users, m1 and m2 in the myfriend group, can use the passwords "m1pass" and "m2pass" respectively to access pages in the /home/httpd/html/backup/ directory.
Implementation steps:
1. Use htpasswd to create a user file, and enter the passwords "m1pass" and "m2pass" for the two users m1 and m2 respectively in the prompt message:
htpasswd -c /home/httpd/secr/.htpasswd m1
htpasswd -c /home/httpd/secr/.htpasswd m2
2. To create a group file, use the "vi /home/httpd/secr/.htgroup" command to create the .htgroup file and write the following line:
myfriend:m1 m2
3. Create the .htaccess file, use the "vi /home/httpd/html/backup/.htaccess" command, and write the following lines:
AuthName My Friend Only
AuthType Basic
AuthUserFile /home/httpd/secr/.htpasswd
AuthGroupFile /home/httpd/secr/.htgroup
require group myfriend