How to install Google Authenticator on Linux

Question: I want to use Google Authenticator to set up two factor authentication. How can I install Google Authenticator on [insert your Linux distro]?

Google Authenticator is an application which can generate time-based one-time passcode to be used for two-factor authentication. You can install Google Authenticator on Linux as a pre-built package or by building it from the source.

Install Google Authenticator as a Pre-built Package

For those of you who don't want to build Google Authenticator, it is available as a pre-built package on several Linux distros. The pre-built package contains Google Authenticator binary and its PAM module.

To install Google Authenticator on Ubuntu:

$ sudo apt-get install libpam-google-authenticator

To install Google Authenticator on Fedora:

$ sudo yum install google-authenticator

To install Google Authenticator on CentOS, first enable EPEL repository, and then run:

$ sudo yum install google-authenticator

Compile Google Authenticator on Linux

First, install prerequisites for building Google Authenticator.

On Debian, Ubuntu or Linux Mint:

$ sudo apt-get install wget make gcc libpam0g-dev

On CentOS, Fedora or RHEL:

$ sudo yum install wget make gcc pam-devel

Then download the source code of Google Authenticator, and compile it as follows.

$ wget https://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2
$ tar xvfvj libpam-google-authenticator-1.0-source.tar.bz2
$ cd libpam-google-authenticator-1.0
$ make

If build is successful, you will see pam_google_authenticator.so and google-authenticator created in the directory.

Finally, go ahead and install Google Authenticator.

$ sudo make install

For instructions on how to set up two-factor authentication for SSH logins with Google Authenticator, refer to this guideline.

Troubleshoot

1. I am getting the following error when compiling Google Authenticator.

fatal error: security/pam_appl.h: No such file or directory

To fix this problem, install the following package.

On Debian, Ubuntu or Linux Mint:

$ sudo apt-get install libpam0g-dev

On CentOS, Fedora or RHEL:

$ sudo yum install pam-devel

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *