1.Install the lib and the program
@raspberrypi:/# sudo apt-get install libpam-google-authenticator
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following extra packages will be installed:
The following NEW packages will be installed:
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 59.7 kB of archives.
After this operation, 117 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libqrencode3 armhf 3.4.3-1 [29.1 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpam-google-authenticator armhf 20130529-2 [30.5 kB]
Fetched 59.7 kB in 1s (48.1 kB/s)
Selecting previously unselected package libqrencode3:armhf.
(Reading database … 35014 files and directories currently installed.)
Preparing to unpack …/libqrencode3_3.4.3-1_armhf.deb …
Unpacking libqrencode3:armhf (3.4.3-1) …
Selecting previously unselected package libpam-google-authenticator.
Preparing to unpack …/libpam-google-authenticator_20130529-2_armhf.deb …
Unpacking libpam-google-authenticator (20130529-2) …
Processing triggers for man-db (18.104.22.168-5) …
Setting up libqrencode3:armhf (3.4.3-1) …
Setting up libpam-google-authenticator (20130529-2) …
Processing triggers for libc-bin (2.19-18+deb8u7) …
2. Start the Google Authenticator program and set it up
Do you want authentication tokens to be time-based (y/n) y
Your new secret key is: DFDFDSFVSDFSDFSDF
Your verification code is 36534654
Your emergency scratch codes are:
Do you want me to update your “/root/.google_authenticator” file (y/n) y
Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
By default, tokens are good for 30 seconds and in order to compensate for
possible time-skew between the client and the server, we allow an extra
token before and after the current time. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) y
If the computer that you are logging into isn’t hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) y
3. Activate Google Authenticator to work with the PAM module and SSH
sudo nano /etc/pam.d/sshd
Add the following line:
auth required pam_google_authenticator.so
sudo nano /etc/ssh/sshd_config
locate ChallengeResponseAuthentication line which is set by default to “no”, and change it to “yes”
sudo /etc/init.d/ssh restart
Warning: Do not close the existing SSH session, open a new SSH session to test your Google Authenticator 2FA :)