Question I want to use Google Authenticator to set up two factor authentication. How can I install Google Authenticator on [insert your Linux distro]?
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
- 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