I currently have my apache server to authenticate via a password file created from htpasswd. Configured as such:

AuthType Basic
AuthName "Secured Site"
AuthUserFile "/etc/apache2/users.passwd"

How can I change this to authenticate via local system accounts and additionaly restrict to only a subset of local system accounts in a specified group?


As suggested by David Z, you can use mod-authnz-external. Use it with pwauth for example.

If you are running Debian or a derivative:

apt-get install libapache2-mod-authnz-external pwauth
a2enmod authnz_external

In your configuration, add

<IfModule mod_authnz_external.c>
  AddExternalAuth pwauth /usr/sbin/pwauth
  SetExternalAuthMethod pwauth pipe

And in the Directory section or your .htaccess file:

    AuthType Basic
    AuthName "Login"
    AuthBasicProvider external
    AuthExternal pwauth
    Require valid-user
    # or
    # Require user jules jim ...

Finally reload the configuration with apache2ctl restart or service apache2 reload.

See also this documentation.

  • 1
    From INSTALL, section "CONFIGURATION" -> "Configurating the External Authenticator" -> "For External Authentication Programs": AddExternalAuth and SetExternalAuthMethod are old-style syntax commands. The new-style syntax uses only one command: DefineExternalAuth pwauth pipe /usr/sbin/pwauth. – sierrasdetandil Dec 14 '15 at 16:28
  • For anyone using pwauth, make sure the pwauth binary has setuid permissions! You can do so with this command: chmod u+s /usr/bin/pwauth. When Apache invokes pwauth and setuid permissions are not set, the status code of 1 (unknown) is always returned. bugs.launchpad.net/ubuntu/+source/pwauth/+bug/579846 – Elliot B. May 31 '17 at 23:26

You probably want to look into something like mod_auth_pam. PAM is the "Pluggable Authentication Module" system and the standard Linux (I'm assuming this is Linux) system login mechanism relies on PAM to do its authentication.

Another option is mod_authnz_external, which will look directly at the /etc/shadow file to authenticate accounts.

EDIT: Apparently mod_auth_pam is no longer maintained (unfortunately), so maybe mod_authnz_external would be a better bet...


The Apache module mod_auth_pam will do exactly this for you. You enable the module, and the config file should look something like

AuthType Basic
AuthName "secure area"
require group staff
require user webmaster

And you're all set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.