通过系统帐户在 Apache 中进行身份验证

Mar*_*ddy 7 authentication apache-2.2

我目前有我的 apache 服务器通过从 htpasswd 创建的密码文件进行身份验证。配置如下:

AuthType Basic
AuthName "Secured Site"
AuthUserFile "/etc/apache2/users.passwd"
Run Code Online (Sandbox Code Playgroud)

如何将其更改为通过本地系统帐户进行​​身份验证并另外限制为仅指定组中本地系统帐户的子集?

miv*_*ivk 9

根据 David Z 的建议,您可以使用 mod-authnz-external。例如,将它与pwauth一起使用。

如果您运行的是 Debian 或衍生版本:

apt-get install libapache2-mod-authnz-external pwauth
a2enmod authnz_external
Run Code Online (Sandbox Code Playgroud)

在您的配置中,添加

<IfModule mod_authnz_external.c>
  AddExternalAuth pwauth /usr/sbin/pwauth
  SetExternalAuthMethod pwauth pipe
</IfModule>
Run Code Online (Sandbox Code Playgroud)

在目录部分或您的 .htaccess 文件中:

    AuthType Basic
    AuthName "Login"
    AuthBasicProvider external
    AuthExternal pwauth
    Require valid-user
    # or
    # Require user jules jim ...
Run Code Online (Sandbox Code Playgroud)

最后使用apache2ctl restart或重新加载配置service apache2 reload

另请参阅此文档


tow*_*owo 2

Apache 模块mod_auth_pam将为您完成此任务。您启用该模块,配置文件应该类似于

AuthType Basic
AuthName "secure area"
require group staff
require user webmaster
Run Code Online (Sandbox Code Playgroud)

一切都准备好了。