Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
Last active September 16, 2015 12:57
Show Gist options
  • Save OpenGrid/d68552609b3e2ff5b702 to your computer and use it in GitHub Desktop.
Save OpenGrid/d68552609b3e2ff5b702 to your computer and use it in GitHub Desktop.
How to install 2FA authentication along with SSH key on Ubuntu 14.04

IMPORTANT never end your ssh session before the configuration is complete because you may loose the possibility to access your server

Install libpam-google-authenticator

apt-get install libpam-google-authenticator

Add you Google authenticator account by running:

google-authenticator

Add your SSH public key to .ssh/authorized_keys

Add to the beginning of /etc/pam.d/sshd

auth required pam_google_authenticator.so

and very importantly comment the line:

@include common-auth

Update file /etc/ssh/sshd_config

Add

AuthenticationMethods publickey,keyboard-interactive:pam

right after #AuthorizedKeysFile %h/.ssh/authorized_keys

If necessary change the following:

ChallengeResponseAuthentication yes

PermitEmptyPasswords no

UsePAM yes

Restart sshd

service ssh restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment