Search code examples
apacheapache2basic-authentication

Is it possible to have two password files in Apache2?


Can I have two AuthUserFile directives in an apache2/sites-enabled/000-default configuration file?

    <Location /repo/trac>
      AuthType Basic
      AuthName "Trac"
      AuthUserFile /etc/apache2/passfile1
      AuthUserFile /etc/apache2/passfile2
      Require valid-user
    </Location>

I want username/password for two types of users.

  • DEV - can access SVN and Trac
  • NOM - can only access Trac

I have two options: keep separate password files for Trac and Svn and include them separately, or have 2 password files in 1 I put DEV in other NOM and include only 1 for svn and include two under trac location.


Solution

  • You should move everything into a single password file and then use groups to control access to particular resources. You can create /etc/apache2/groups with contents along the lines of:

    DEV: bob alice
    NOM: norm fred bart
    

    And then modify your configuration so it looks like this:

    <Location /repo/trac>
      AuthType Basic
      AuthName "Trac"
      AuthUserFile /etc/apache2/passfile
      AuthGroupFile /etc/apache2/groups
      Require group DEV NOM
    </Location>
    

    This would allow members of the DEV and NOM groups to access this resource.

    If you really want to use multiple password files, see the documentation for mod_authn_alias, which has an example that does exactly this.