Google Authenticator module for Apache

In case you want to use the Google Authenticator for your website you can do the following:

Installation

1. Place mod_authn_google.so in /usr/lib/apache2/modules. (Download from: https://code.google.com/archive/p/google-authenticator-apache-module/downloads)

# cp mod_authn_google.so /usr/lib/apache2/modules

2. Load the module in apache2 configuration:

Loadmodule authn_google_module /usr/lib/apache2/modules/mod_authn_google.so

3. Create two-factor folder under apache

# mkdir -p /etc/apache2/two-factor

4. Install linux google-authenticator

# apt-get install libpam-google-authenticator

5. run google-authenticator

# google-authenticator

6. Move the authenticator profile to the correct folder and rename it to the username you are going to log in with.

# mv ~/.google_authenticator /etc/apache2/two-factor/MyUserName

7. Add the basic authentication configuration to the vhost config:

AuthType Basic
AuthName "Google Authenticator Code"
AuthBasicProvider "google_authenticator"
Require valid-user
GoogleAuthUserPath /etc/apache2/two-factor/
GoogleAuthCookieLife 3600
GoogleAuthEntryWindow 2
SSLRequireSSL

8. Restart apache

# /etc/init.d/apache2 restart