问题原文
原帖链接 · ben lemasurier · CC BY-SA 4.0
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
已采纳解答
原帖链接 · ben lemasurier · CC BY-SA 3.0
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 by PAM->auth-yubi. Additional changes were also needed, see below:
(ubuntu 14.04 - trusty):
/etc/pam.d/yubi-auth
auth required pam_yubico.so mode=client try_first_pass id=<id> key=<key>
Note: you can obtain your access ID and secret key here
/etc/pam.d/sshd
# Standard Un*x authentication.
#@include common-auth
# Yubikey auth
@include yubi-auth
/etc/ssh/sshd_config
UsePAM yes
ChallengeResponseAuthentication no
AuthenticationMethods publickey,password
PasswordAuthentication yes
service ssh restart
Verification
SSH from a remote host without a public key
root@0a6442bcb21c:/# ssh [email omitted]
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is ea:2a:e3:98:35:72:66:b1:e0:65:6b:3f:60:8a:af:ab.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.20' (ECDSA) to the list of known hosts.
Permission denied (publickey).
SSH from a remote host with a public key
$ ssh [email omitted]
Authenticated with partial success.
[email omitted]'s password:
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-33-generic x86_64)
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
