Set Apache login Password verification

Source: Internet
Author: User

I. Edit the virtual directory configuration file and set the authentication method


Alias/test "/var/www/test"
<directory "/var/www/test" >
Options Indexes MultiViews
AllowOverride authconfig #表示进行身份验证
Order Allow,deny
Allow from all
</Directory>

Second, create the. htaccess file in the site Directory
Vim/var/www/test/.htaccess
AuthName "Test" #此处为描述, but after experimentation, it seems to be set as the name of the virtual directory
AuthType Basic validation type
AUTHUSERFILE/VAR/WWW/TEST/.HTPASSWD #密码文件的路径
Require Valid-user

#密码文件推荐使用. htpasswd because the Apache default system does not allow external reads to the file that begins with ". HT", the safety factor is a bit higher.
The last "require" of the #.htaccess file tells the server which users can enter. Require valid-user means that any one of the. HTPASSWD can be entered. You can also specify that someone on the list or a few people can pass, using require user username or require user username1 username2 Username3. You can also specify that a group of people can pass, using the Require group groupname.

File permissions
-rw-r--r--. htaccess
-rwxr--r--. htpasswd #密码文件如果没有rwx权限, may fail validation

Third, create user password

is to create an Apache authenticated user
Htpasswd-c/VAR/WWW/TEST/.HTPASSWD User Name
#第一次创建用户要用到-C parameter is added to the user for the 2nd time without the-c parameter
Htpasswd-m. htpasswd User Name change password
htpasswd-d. htpasswd User name Delete user

/*------------------------------------------------------

PS can also boil 1, 2 steps to the same step, as follows:

Alias/test "/var/www/test"
<Directory/var/www/test>
Options Indexes MultiViews
AuthType Basic #类型
AuthName "Welcome Test"
AUTHUSERFILE/VAR/WWW/TEST/.HTPASSWD #密文配置文件路径
Require valid-user = user Test #test as username if there are other users in this column after test
# Order Allow,deny
# Allow from all
</Directory>

--------------------------------------------------------*/


Restart Apache,ok! Restart Method: Service httpd restart

Iv. Access through user groups

alias/test01 "/data/web/test01/"
<Directory/data/web/test01>
Options Indexes MultiViews
AuthType Basic
AuthName "Welcome Test"
Authuserfile/etc/httpd/httppwd
Authgroupfile/etc/httpd/httpgrp #用户组文件路径
Require group admin #admin are user groups
</Directory>

Create a user group configuration file

Vi/etc/httpd/httpgrp #创建路径与配置文件中指定文件相同

The content is as follows: Admin:test #注意test is a user that has been created, and if there are other users in the group, one arrangement is separated by a space

Restart Apache ok!

Set Apache login Password verification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.