Set apacheweb server password authentication
Go straight to the topic !!!
1. You need to modify the main configuration file of httpd. It is installed in/etc/httpd/conf/httpd. conf by default.
2. vi edit this file
3. Several lines of code need to be modified
Find And To modify the information.
A. Change AllowOverride None to AllowOverride AuthConfig.
B. Add AuthType Basic
C. Add AuthName "My private website ..."
D. Add the User File AuthUserFile "/etc/httpd/conf/htpasswd"
E. Add the User Require user tom jerry (if you want users in htpasswd to have access, change it to Require valid-User)
4. Create a password file
# Htpasswd-c-m/etc/httpd/conf/htpasswd tom
Enter the tom password twice as prompted, and then create the jerry user.
# Htpasswd-m/etc/httpd/conf/htpasswd jerry
Note:-c cannot be used here, because-c Indicates creating a password file. It is only required if there is no password file. If there is a password file, the original one will be deleted directly, in addition,-m indicates that the added user has been encrypted in MD5 mode.
If you delete a user, use the-D option, for example, # htpasswd-D/etc/httpd/conf/htpasswd tom.
5. Restart the web Service
# Service httpd restart
The above section describes how to create a user password, that is, to restrict some users. In fact, httpd also supports group restrictions. The following section describes how to create a user password --------------------
If you want to perform operations on a group, do the following:
1. You need to modify the main configuration file of httpd. It is installed in/etc/httpd/conf/httpd. conf by default.
2. vi edit this file
3. Several lines of code need to be modified
Find And To modify the information.
A. Change AllowOverride None to AllowOverride AuthConfig.
B. Add AuthType Basic
C. Add AuthName "My private website ..."
D. Add the User File AuthUserFile "/etc/httpd/conf/htpasswd"
E. Add the group file AuthGroupFile "/etc/httpd/conf/htgroup"
F. Add the Require group mygroup1 mygroup2
4. Create a password file
# Htpasswd-c-m/etc/httpd/conf/htpasswd tom
Enter the tom password twice as prompted, and then create the jerry user.
# Htpasswd-m/etc/httpd/conf/htpasswd jerry
Note:-c cannot be used here, because-c Indicates creating a password file. It is only required if there is no password file. If there is a password file, the original one will be deleted directly.
5. Create a group file
# Vim/etc/httpd/conf/htgroup
(Add the content to the file)
Mygroup1: tom jerry
Mygroup2: tom
Save and exit. Note that the user must exist in the password file.
6. Restart the web Service
# Service httpd restart
Now you can see that you need to enter the verification password.