Apache 模块 mod_authn_file

Description:使用文本文件的用户身份验证
Status:Base
Module Identifier:authn_file_module
Source File:mod_authn_file.c
Compatibility:在 Apache 2.1 及更高版本中可用

Summary

此模块提供身份验证前端(例如mod_auth_digestmod_auth_basic),以通过在纯文本密码文件中查找用户来对用户进行身份验证。 mod_authn_dbm提供了类似的功能。

使用mod_auth_basicmod_auth_digest时,此模块通过AuthBasicProviderAuthDigestProviderfile值调用。

AuthUserFile Directive

Description:设置一个文本文件的名称,该文件包含用于身份验证的用户和密码列表
Syntax:AuthUserFile file-path
Context:directory, .htaccess
Override:AuthConfig
Status:Base
Module:mod_authn_file

AuthUserFile伪指令设置文本文件的名称,该文本文件包含用户列表和用于用户认证的密码。 File-path 是用户文件的路径。如果不是绝对的,则将其视为相对于ServerRoot

用户文件的每一行都包含一个用户名,后跟一个冒号,然后是加密的密码。如果多次定义相同的用户 ID,则mod_authn_file将使用第一个出现的用户名来验证密码。

加密的密码格式取决于所使用的身份验证前端(例如mod_auth_basicmod_auth_digest)。有关更多信息,请参见Password Formats

对于mod_auth_basic,请使用 Utilhtpasswd,该 Util 是作为二进制发行版的一部分安装的,或者可以在src/support中找到。有关更多详细信息,请参见man page。简而言之:

创建一个以username作为初始 ID 的密码文件Filename。它将提示 Importing 密码:

htpasswd -c Filename username

在密码文件Filename中添加或修改username2

htpasswd Filename username2

请注意,搜索大型文本文件的效率非常低;应该使用AuthDBMUserFile

对于mod_auth_digest,请改用htdigest。请注意,您不能在同一文件中混合用于摘要身份验证和基本身份验证的用户数据。

Security

确保AuthUserFile存储在 Web 服务器的文档树之外。请勿将其放在受保护的目录中。否则,Client 端可能可以下载AuthUserFile