How to install Google Authenticator on Linux

Last updated on November 26, 2020 by Dan Nanni

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.

Install Google Authenticator on Ubuntu

$ sudo apt-get install libpam-google-authenticator

Install Google Authenticator on Fedora

$ sudo yum install google-authenticator

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

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean