Install / Setup Google Authenticator in Ubuntu 13.04, 12.04

August 4, 2013 — 3 Comments

This simple tutorial is going to show you how to install and setup Google Authenticator to secure your Ubuntu SSH remote login by two-factor authentication.

Google provides this application for various smartphone platforms. With it, you can secure your account by logging in with a frequently-changing authentication code. So far, I’m using this in WordPress Login, Ubuntu Server SSH Login, Linode VPS Login. As I know, Google Authenticator also works on Amazon Web Services, App.net, Dropbox, and more.

Install Google Authenticator in Ubuntu:

Since Ubuntu 12.04 Precise, the Google Authenticator PAM module is available in the universe repository by default. Just open Ubuntu Software Center, search for and install libpam-google-authenticator package

google authenticator ubuntu

Once installed, press Ctrl+Alt+T to open terminal. Run below command to create a key and display a QR code which you can scan using the smartphone app. The emergency codes can be used when you don’t have your phone.

google-authenticator

google authenticator secret key

To enable two-step authentication for SSH login, add the line “auth required pam_google_authenticator.so” (witout quotes) into /etc/pam.d/sshd. To do so, run below command in terminal:

sudo sh -c 'echo "auth required pam_google_authenticator.so" >> /etc/pam.d/sshd'

Also add the line “ChallengeResponseAuthentication yes” (without quotes) to /etc/ssh/sshd_config, you can do it by running below command:

sudo sh -c 'echo "ChallengeResponseAuthentication yes" >> /etc/ssh/sshd_config'

Finally restart SSH service on Ubuntu:

sudo /etc/init.d/ssh restart

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on Google Plus or email to ubuntuhandbook1@gmail.com

3 responses to Install / Setup Google Authenticator in Ubuntu 13.04, 12.04

  1. Thanks for this tip.

  2. Thanks for the tip. Seems to work fine in Ubuntu 15.10 as well

  3. In Ubuntu 16.04 we also need to add/change “UsePAM yes” in /etc/ssh/sshd_config.

Leave a Reply

*

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>