News for hackers. Stuff that matters.
Re:Add two-factor authentication to your ssh in 30 seconds by cs702 on Tuesday August 28, 2012 @03:04PM (#4445303)
Using a third-party service like authy.com has its advantages, but if you prefer, you can get two-factor authentication in the latest Ubuntu without involving a third party by installing libpam-google-authenticator from Ubuntu's "universe" repository.

Here's how you do it: first, sudo apt-get install libpam-google-authenticator; second, run google-authenticator as the user you will access remotely and follow the instructions; then, edit /etc/pam.d/sshd, and add "auth required pam_google_authenticator.so" in a new line; edit /etc/ssh/sshd_config and add (or change) the ChallengeResponseAuthentication line so it reads "ChallengeResponseAuthentication yes"; and finally, sudo service ssh restart to restart the ssh server.

More info is available from the packager of libpam-google-authenticator[1], and from the Google Authenticator PAM module's README.[2]

--

[1] http://blog.theroux.ca/security/ubuntu-2-step-authentication...

[2] http://code.google.com/p/google-authenticator/source/browse/...

--

Edits: Corrected typos; added more context.

Re:Add two-factor authentication to your ssh in 30 seconds by danielpal on Tuesday August 28, 2012 @03:11PM (#4445344)
The biggest problems is you can't use ssh_keys with this setup. Its too restrictive, and certificates are a must for ssh.

Also what happens if you loose your cellphone? We thought about this and for us the possibility of loosing access to the server fully was too much.

Re:Add two-factor authentication to your ssh in 30 seconds by jlgreco on Tuesday August 28, 2012 @03:51PM (#4445559)
Unless I am mistaken, it should be possible to configure opensshd to first try using keys, then fall back on UsePAM only if that fails (similar to how sshd will normally fall back on PasswordAuthentication).

If not, it might be possible to configure PAM with some sort of keys module set to 'sufficient', then have PAM fall back on two-factor auth paired with pam_unix.

In fact, I'll see if I can get either of those working a bit later today. Seems like it could be neat.

Re:Add two-factor authentication to your ssh in 30 seconds by guiambros on Wednesday August 29, 2012 @12:54AM (#4447156)
Another option is to whitelist your ip address, and then require 2-factor auth only when you're connecting from a non-whitelisted ip address.

Of course this leaves you a vulnerable to ip spoofing, but adds a ton of convenience and could be a good trade-off.

Re:Add two-factor authentication to your ssh in 30 seconds by meik on Wednesday August 29, 2012 @04:22AM (#4447560)
Yeah but (blind) IP spoofing over the Internet is infeasible nowadays. Maybe 15 years ago when ISN randomization was not the rule (successful attack described in http://web.textfiles.com/hacking/shimomur.txt)

But that's correct, in recent openssh versions, it seems that you can add specific-host-only rules for authentication etc.

Re:Add two-factor authentication to your ssh in 30 seconds by keidian on Tuesday August 28, 2012 @03:29PM (#4445446)
You could probably do a hack to let the user login with ssh key and then immediately force the second factor auth to be run, booting the user out if they didn't pass it. Not the best way, but one option.

I also believe I once ran across a patch someone had done to the login code to allow both to be required, I can't find the link right off though as I'm at work currently. If I find it, I'll add it here

Re:Add two-factor authentication to your ssh in 30 seconds by j_s on Tuesday August 28, 2012 @03:45PM (#4445533)
A ForceCommand example (for Yubikey) is documented here: http://www.tuxz.net/blog/archives/2010/03/17/how_to_quickly_...
Re:Add two-factor authentication to your ssh in 30 seconds by rsync on Tuesday August 28, 2012 @03:52PM (#4445562)
Yes, I have seen a patch as well that allowed you to require both an ssh key and a password ... it was an old patch, though, and I can't imagine it would apply cleanly to any recent OpenSSH ...

This is on our list to pay for someone to do, and we'll release it when they do ... it will probably be FreeBSD-centric, but if it's against OpenSSH generally, it should be usable by others...

Re:Add two-factor authentication to your ssh in 30 seconds by dalore on Tuesday August 28, 2012 @05:46PM (#4446040)
What happens if you lose your normal password? Why you boot up into single user mode using the console like the old days of when you forgot the root password.
Re:Add two-factor authentication to your ssh in 30 seconds by count on Tuesday August 28, 2012 @05:58PM (#4446099)
And how do you do that with cloud instances? :)
Re:Add two-factor authentication to your ssh in 30 seconds by pixelcort on Tuesday August 28, 2012 @07:06PM (#4446334)
Some VPS providers offer "console" access to the machine, which would probably allow someone to drop down into single user mode.

http://www.linode.com/faq.cfm#do-you-provide-console-access

Re:Add two-factor authentication to your ssh in 30 seconds by Ralith on Tuesday August 28, 2012 @06:08PM (#4446134)
Same way you do when you forget the root password on a normal configuration.
Re:Add two-factor authentication to your ssh in 30 seconds by justincormack on Wednesday August 29, 2012 @04:46AM (#4447616)
Install a new instance! Its all disposable hardware.
Re:Add two-factor authentication to your ssh in 30 seconds by cs702 on Tuesday August 28, 2012 @03:15PM (#4445368)
danielpal: google-authenticator prints out emergency scratch codes you can use if you lose your cellphone :-)
Re:Add two-factor authentication to your ssh in 30 seconds by danielpal on Tuesday August 28, 2012 @03:21PM (#4445404)
Yeah but in reality no-one writes it down. I actually use Google-Auth for my Gmail, but I forgot were I wrote this number down(it was a couple of years ago). Keeping a scratch code for each new server is a pain.
Re:Add two-factor authentication to your ssh in 30 seconds by Karunamon on Tuesday August 28, 2012 @03:42PM (#4445522)
>Yeah but in reality no-one writes it down.

Then that's a process problem that can be solved. It would take a trivial amount of time to screenshot the page and stash them in your wiki or similar.

Re:Add two-factor authentication to your ssh in 30 seconds by pooriaazimi on Tuesday August 28, 2012 @10:10PM (#4446762)
Those who don't write it down deserve to be locked out.

I've written down mine on three different pieces of paper (in my wallet, my bag and my closet), and also took a screenshot from it and `gpg`-ed it (with a passphrase, so no one can open it unless they know the password) and stored it in a few online repositories, as well as a friend's mailbox.

So, I'll never be locked out from my account.

Re:Add two-factor authentication to your ssh in 30 seconds by jonny_eh on Wednesday August 29, 2012 @04:05AM (#4447521)
It's the only sane thing to do!
Re:Add two-factor authentication to your ssh in 30 seconds by halostatue on Tuesday August 28, 2012 @03:37PM (#4445498)
My scratch codes are in 1Password (for my personal accounts) and LastPass (for work accounts).
Re:Add two-factor authentication to your ssh in 30 seconds by charliepark on Wednesday August 29, 2012 @05:12AM (#4447673)
People really should do this. It takes 10 seconds, and eliminates having any paper to lose (or keep secure). Copy and paste, and you're done.
Re:Add two-factor authentication to your ssh in 30 seconds by dalore on Tuesday August 28, 2012 @05:45PM (#4446037)
Mine are printed out and stored in my safe. They are never used.
Re:Add two-factor authentication to your ssh in 30 seconds by duaneb on Wednesday August 29, 2012 @12:44PM (#4449514)
> Yeah but in reality no-one writes it down. I actually use Google-Auth for my Gmail, but I forgot were I wrote this number down(it was a couple of years ago). Keeping a scratch code for each new server is a pain.

This is your problem. I keep mine (for multiple services) in my wallet, and it's worked out excellently.

Re:Add two-factor authentication to your ssh in 30 seconds by arjunnarayan on Tuesday August 28, 2012 @04:19PM (#4445689)
Mine are written down in a post-it note stuck to the inside back-flap of my passport.
Re:Add two-factor authentication to your ssh in 30 seconds by ikonst on Tuesday August 28, 2012 @04:24PM (#4445713)
You can use the same key for all the servers. Just copy the files generated by the 'google-authenticator' app. I don't see any less security in that.
Re:Add two-factor authentication to your ssh in 30 seconds by ikonst on Tuesday August 28, 2012 @04:19PM (#4445688)
I use ssh keys with this setup. If I login with an ssh key, I don't need the OTP.
Re:Add two-factor authentication to your ssh in 30 seconds by vegardx on Tuesday August 28, 2012 @05:38PM (#4446009)
How did you manage to do this? You'd have to use PAM for this to work, and PAM and key-based authentication is mutually exlusive, as far as I know.
Re:Add two-factor authentication to your ssh in 30 seconds by gregwebs on Tuesday August 28, 2012 @11:37PM (#4446978)
If you use a google voice number you can just point it to a new phone.
Re:Add two-factor authentication to your ssh in 30 seconds by justincormack on Wednesday August 29, 2012 @04:47AM (#4447618)
Don't you need to login to do that? Using 2 factor auth..
Re:Add two-factor authentication to your ssh in 30 seconds by ikonst on Wednesday August 29, 2012 @10:44AM (#4448788)
Yes, so use your backup keys, or a secondary phone number, or a secondary email address... plenty of options.
Re:Add two-factor authentication to your ssh in 30 seconds by draebek on Tuesday August 28, 2012 @04:06PM (#4445621)
Thanks for the instructions, I like the fact that Google Authenticator doesn't need to contact their servers (or at least that's how I understand it). Sounds like you could preserve the use of SSH public key authentication by using Google Authenticator in combination with a ForceCommand; I'll have to look in to that.

Anyone set up Google Authenticator to only challenge me on a host every N minutes or something like that? I.e., first login requires two-factor auth, subsequent logins don't for at least 30 minutes? Seems like it'd be irritating to keep popping my phone out every time I connect to a remote server.

Re:Add two-factor authentication to your ssh in 30 seconds by jiri on Wednesday August 29, 2012 @04:24AM (#4447563)
Partial solution: it may be useful to use Host * and ControlMaster auto in your .ssh/config to reuse connection so you do not need to authorize all the time.
Re:Add two-factor authentication to your ssh in 30 seconds by ersii on Tuesday August 28, 2012 @03:40PM (#4445513)
Google Authenticator is pretty much a third-party service as well.

Unless I'm mistaken in how Google Authentiator works - of course. If so, please fill in my blank :-)

Re:Add two-factor authentication to your ssh in 30 seconds by paxswill on Tuesday August 28, 2012 @03:52PM (#4445567)
Using pam-google-authenticator does not depends on Google, they just wrote widely available apps and a PAM module[0] that implement HOTP[1] and TOTP[2]. Basically, you have a seed and a counter that you hash together. When adding a device, the seed and counter are synced with the device. When logging in, the server generates the proper code, then verifies it got that code. The major difference between the two algorithms is that TOTP uses time as its counter, while HOTP uses a manually increased counter.

[0] http://code.google.com/p/google-authenticator/

[1] http://en.wikipedia.org/wiki/HOTP

[2] http://en.wikipedia.org/wiki/Time-based_One-time_Password_Al...

Re:Add two-factor authentication to your ssh in 30 seconds by drivebyacct2 on Wednesday August 29, 2012 @01:23AM (#4447216)
You are mistaken. I'm not sure what blank to fill in. Google Auth use OATH for their two factor auth. Using the reference package just gives you their PAM module. It doesn't require hitting their servers or anything.

http://code.google.com/p/google-authenticator/

Re:Add two-factor authentication to your ssh in 30 seconds by pja on Wednesday August 29, 2012 @08:29AM (#4448154)
If you run google-authenticator with no arguments it hits Google's servers in order to generate a QRcode for your phone to scan.

So you are in fact handing over your 2-factor auth key to Google when you run google-authenticator. There's no actual need for the binary to do this (although it obviously makes the key entry on the phone much less error-prone) and there don't seem to be any command line arguments that would turn it off either. doesn't do this at all -- see below. (can I do strikethrough on HN?)

Re:Add two-factor authentication to your ssh in 30 seconds by mryan on Wednesday August 29, 2012 @08:47AM (#4448195)

    So you are in fact handing over your 2-factor auth key to Google when
    you run google-authenticator
Unless things have changed a lot since I last used this, this is not entirely correct. The binary will print out a URL - the QR code is only generated if you hit this URL.

If you visit this URL, you are sending the "QR-encoded" (not exactly, but you know what I mean) version of the key to Google's servers.

As long as you do not visit this link, you will not send your key to Google's servers.

Re:Add two-factor authentication to your ssh in 30 seconds by pja on Wednesday August 29, 2012 @08:52AM (#4448213)
Can't reply to mryan, but I'd just checked this before coming back to HN & indeed, google-authenticator doesn't make any network connections when invoked & it generates the QR-code locally.

So don't hit that URL if you don't want Google to know your 2-factor auth data!

Re:Add two-factor authentication to your ssh in 30 seconds by jlgreco on Tuesday August 28, 2012 @03:27PM (#4445441)
Interestingly it appears this Authy method does not use PAM. I wonder if there is a reason for that, since a PAM module would be a good deal more flexible (this sort of thing is what PAM is for after all).
Re:Add two-factor authentication to your ssh in 30 seconds by danielpal on Tuesday August 28, 2012 @08:53PM (#4446592)
The basic reason is because we don't use passwords. We always use public/private certificates on all of our machines. With PAM you have to use passwords. We'll release a version soon that works with PAM, but I recommend you switch to using authorized_keys with certificates. Not only is it much more secure, it's also much nicer to use.
Re:Add two-factor authentication to your ssh in 30 seconds by jlgreco on Tuesday August 28, 2012 @10:53PM (#4446871)
I do use authorized_keys, though PAM is good for a lot more than just sshd; that's why I say it is more flexible. For example, I could see two factor authentication being used to log into shared workstations through XDM/GDM. This would eliminate the possibility that your users are sharing passwords for their accounts.

Also, the way I would intend on using this is such that if your public key is in authorized_keys, you log in like normal. If not, you authenticate with PAM using both your unix password (or ldap or whatever you have configured) and your 2nd authentication system. I log into one or two of my servers from strange computers often enough that disabling password authentication entirely on those servers is limiting.

Re:Add two-factor authentication to your ssh in 30 seconds by danielpal on Wednesday August 29, 2012 @09:13AM (#4448320)
Yeah we'll release a PAM module soon so you can do this. If you don't want to wait, you could write one. Just look at this module, it's fairly simple. The API is really straight forward.
Re:Add two-factor authentication to your ssh in 30 seconds by Ralith on Tuesday August 28, 2012 @06:10PM (#4446138)
Most probably, they didn't know about PAM.
Re:Add two-factor authentication to your ssh in 30 seconds by danielpal on Tuesday August 28, 2012 @08:48PM (#4446579)
Not at all. We understand PAM and we plan to release a version that works with PAM. But we don't like passwords, we much rather use public/private ssh keys instead of users with passwords. It's not only much better user experience but is also much more secure.