| « Beyond SQLi: Obfuscate and Bypass | Regularly cleaning your consolidated.db file on the iPhone » |
Use Google Authenticator to login to a Linux PC
You can use this existing implementation and Google Authenticator application with SSH via an included PAM in the Google Authenticator open source application.
Download the Google Authenticator application
First, download and install Google Authenticator on your Iphone/Android/Blackberry.
Compile, install, configure Google authenticator PAM
You may need a few dependencies. On Debian I was missing ‘mercurial libqrencode3 libpam0g-dev’.
$ hg clone https://google-authenticator.googlecode.com/hg/ google-authenticator/
$ cd google-authenticator/libpam/
$ make
$ sudo make install
$ sudo vi /etc/pam.d/sshd
Add the following line to the end of /etc/pam.d/sshd (add at beginning if you want to request the verification code first, I prefer it last): auth required pam_google_authenticator.so
You also need to update /etc/ssh/sshd_config and add/update: ChallengeResponseAuthentication yes
Setup your user to require two-factor authentication
As a user, you can now run ‘google-authenticator’. This will generate a secret key, and add a file to your home directory that the newly installed PAM uses.
$ google-authenticator
Do you want me to update your "~/.google_authenticator" file (y/n) y
Your new secret key is: APAXADA3AEAUAGAQ
Your verification code is 5618181
Your emergency scratch codes are:
14111017
14141013
11121019
14181616
13181615
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) n
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
Note: The emergency scratch codes are one-time use verification codes in the event your phone is unavailable.
Configure this new secret key in Google Authenticator
In your Google Authenticator application on your phone, add this new secret key that was generated in the previous step. Note, a URL is also displayed, that can be scanned from your Google Authenticator application.
Wrapping up the setup
You will now need to restart SSH for the pam/ssh changes to activate.
At this point, you will want to stay logged into the server while you test in another shell.
Testing
Test that two-factor authentication is working.
$ ssh example.com
Password:
Verification code:
[user@host ~]$
Enter the verification code as shown on your phone.
Your SSH sessions are now protected with two factor authentication.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)