Straight to the theme!!!
1. You need to modify the HTTPD master profile, which is installed by default at/etc/httpd/conf/httpd.conf
2.VI edit this file
3. Need to modify a few lines of code
Find the contents of <directory "/var/www/html" > and </Directory>, modify the information
A. Change allowoverride none to allowoverride authconfig first
B. Adding AuthType Basic
C. Add AuthName "My private website ..."
D. Adding user files to allow access AuthUserFile "/ETC/HTTPD/CONF/HTPASSWD"
E. Add the user who is allowed to access require users Tom Jerry (change to require valid-user if you want htpasswd inside users to be accessible)
4. Create a password file
# htpasswd-c-M/ETC/HTTPD/CONF/HTPASSWD Tom
Enter Tom's password as prompted, enter two times, and then create a Jerry user
# htpasswd-m/ETC/HTTPD/CONF/HTPASSWD Jerry
Note: Here must no longer use the-C, because the-C means to create a password file, only if there is no password file is needed, the password file will be deleted directly from the original, plus-m indicates that the added user has been MD5 encrypted way
If you delete a user then use the-D option, such as # htpasswd-d/etc/httpd/conf/htpasswd Tom deletes the Tom user
5. Restart the Web service
#service httpd Restart
-----------------------------------------------------------------------------above is to create a user password, that is, to restrict certain users, In fact, HTTPD also support the restrictions on the group, which is explained below--------------------
If you need to operate on a group, do this:
1. You need to modify the HTTPD master profile, which is installed by default at/etc/httpd/conf/httpd.conf
2.VI edit this file
3. Need to modify a few lines of code
Find the contents of <directory "/var/www/html" > and </Directory>, modify the information
A. Change allowoverride none to allowoverride authconfig first
B. Adding AuthType Basic
C. Add AuthName "My private website ..."
D. Adding user files to allow access AuthUserFile "/ETC/HTTPD/CONF/HTPASSWD"
E. Adding a group file that is allowed access AuthGroupFile "/etc/httpd/conf/htgroup"
F. Adding a group to allow access require group Mygroup1 mygroup2
4. Create a password file
# htpasswd-c-M/ETC/HTTPD/CONF/HTPASSWD Tom
Enter Tom's password as prompted, enter two times, and then create a Jerry user
# htpasswd-m/ETC/HTTPD/CONF/HTPASSWD Jerry
Note: Here must no longer use-C, because the-C means to create a password file, only if there is no password file, the password file will be deleted directly from the original
5. Create a group file
#vim/etc/httpd/conf/htgroup
(Add content to the file)
Mygroup1:tom Jerry
Mygroup2:tom
Save the exit, note that the user here must be in the password file exists in the user.
6. Restart the Web service
#service httpd Restart
Now you can see that you need to enter a verification password.
Set Apache Web server password Authentication