I have got this slick little yubikey and I want to add an additional layer of security when authenticating ssh sessions. On the server side I've already disabled password authentication and only permit the use of ssh keys when logging in.
The problem is, after configuring sshd and PAM for yubikey auth, sshd still only requires an ssh key, I'm never asked to provide a response from the yubikey.
How do I require both and ssh key and a yubikey?
(ubuntu 14.04 - trusty)
/etc/pam.d/common-auth
:
auth required pam_yubico.so mode=client try_first_pass id=<id> key=<secret>
auth [success=1 default=ignore] pam_unix.so nullok_secure try_first_pass
# here's the fallback if no module succeeds
auth requisite pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
auth required pam_permit.so
# and here are more per-package modules (the "Additional" block)
auth optional pam_cap.so
# end of pam-auth-update config
/etc/ssh/sshd_config
:
...
PasswordAuthentication no
ChallengeResponseAuthentication yes
UsePAM yes
Ok, I kept at it and I think I've come up with a reasonable solution. The primary thing I was previously missing was sshd's
AuthenticationMethods publickey,password
. This enforces the requirement for both a publickey and a password -- "password"s now being handled byPAM->auth-yubi
. Additional changes were also needed, see below:(ubuntu 14.04 - trusty):
/etc/pam.d/yubi-auth
Note: you can obtain your access ID and secret key here
/etc/pam.d/sshd
/etc/ssh/sshd_config
service ssh restart
Verification
SSH from a remote host without a public key
SSH from a remote host with a public key
Improvement
It would be nice to see "Yubikey Auth:" instead of "password:" from the remote ssh server when authenticating.
What happens when the ssh server is unable to contact yubico's auth verification system? An ideal solution would be entirely self-contained.
Comments and suggestions appreciated.
Setting up 2FA with Yubikey can be tricky (thought there is openssh patch for U2F), but the easiest way is probably the one described on Yubico official website.
It is basically the way of storing your private key on the Yubikey and protecting it with PIN. It is not exactly the 2FA you are described (but it is something what you have and and what you know), but it increases the security even more (Yubikey locks after some unsuccessful tries).
TL:DR;