TL:DR;

TL:DR;

我有这个漂亮的小型 yubikey,我想在验证 ssh 会话时增加额外的安全层。在服务器端,我已经禁用密码验证,并且只允许在登录时使用 ssh 密钥。

问题是,在为 yubikey 身份验证配置 sshd 和 PAM 后,sshd 仍然只需要 ssh 密钥,而从未要求我提供 yubikey 的响应。

我如何要求两个都和 ssh 密钥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

答案1

好的,我继续努力,我想我已经想出了一个合理的解决方案。我之前最主要缺少的是 sshd AuthenticationMethods publickey,password。这强制要求公钥密码——“密码”现在由 处理PAM->auth-yubi。还需要进行其他更改,如下所示:

(Ubuntu 14.04-值得信赖):

/etc/pam.d/yubi-auth

auth    required pam_yubico.so mode=client try_first_pass id=<id> key=<key>

注:您可以获取您的访问ID和密钥这里

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

确认

从远程主机进行 SSH没有公钥

root@0a6442bcb21c:/# ssh [email protected]
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公钥

$ ssh [email protected]
Authenticated with partial success.
[email protected]'s password:
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-33-generic x86_64)

改进

如果在进行身份验证时,从远程 ssh 服务器看到“Yubikey Auth:”而不是“password:”那就太好了。

当 ssh 服务器无法连接 yubico 的身份验证系统时会发生什么?理想的解决方案是完全独立的。

欢迎提出意见和建议。

答案2

使用 Yubikey 设置 2FA 可能比较棘手(虽然有 opensshU2F 补丁),但最简单的方法可能是Yubico官方网站

它基本上是将您的私钥存储在 Yubikey 上并用 PIN 保护它的方式。它并不完全是您描述的 2FA(但它是您所还有你知道),但它进一步提高了安全性(Yubikey 在几次尝试失败后会锁定)。

TL:DR;

OPENSC_LIBS=`locate opensc-pkcs11.so`
yubico-piv-tool -s 9a -a generate -o public.pem
yubico-piv-tool -a verify-pin -P 123456 -a selfsign-certificate -s 9a \
  -S "/CN=SSH key/" -i public.pem -o cert.pem
yubico-piv-tool -a import-certificate -s 9a -i cert.pem
ssh-keygen -D $OPENSC_LIBS/opensc-pkcs11.so -e
ssh -I $OPENSC_LIBS/opensc-pkcs11.so [email protected]

相关内容