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:
In your configuration, add
And in the Directory section or your .htaccess file:
Finally reload the configuration with
apache2ctl restart
orservice apache2 reload
.See also this documentation.
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 maybemod_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 likeAnd you're all set.
I just came across the same issue. Here's my solution since
mod_auth_pam
is dead and no one has addressed the original question,I'm using Ubuntu 18.04, so flavor the package installation to your own system. For this example, I'm hosting a directory
/var/www/data
and only want users in thedata
group to have access. I'm assuming you have an Apache installation running and thedata
group already created.As mentioned before, you'll need to grab
pwauth
and theauthnz
software. Additionally, you will needmod-authz-unixgroup
for group authentication. You can install them using,Next, change the permissions of pwauth (this was fixed on 2020-06-02, but I'll leave this here for older releases) by using,
Then, write up your apache2 VirtualHost configuration. Here's a very simple example,
Finally, you'll need to reload, restart, and check the status of Apache for errors.