AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 742054
Accepted
ben lemasurier
ben lemasurier
Asked: 2015-12-10 19:51:39 +0800 CST2015-12-10 19:51:39 +0800 CST 2015-12-10 19:51:39 +0800 CST

带有 yubikey 的 SSH 两因素身份验证 (2FA)

  • 772

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

问题是,在为 yubikey auth 配置 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
ssh
  • 2 2 个回答
  • 1544 Views

2 个回答

  • Voted
  1. Best Answer
    ben lemasurier
    2015-12-11T06:48:27+08:002015-12-11T06:48:27+08:00

    好的,我坚持下去,我想我已经想出了一个合理的解决方案。我之前缺少的主要内容是 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 和密钥

    /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

    确认

    来自没有公钥的远程主机的 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 的 auth 验证系统时会发生什么?理想的解决方案将是完全独立的。

    意见和建议表示赞赏。

    • 5
  2. Jakuje
    2015-12-11T00:46:17+08:002015-12-11T00:46:17+08:00

    使用 Yubikey 设置 2FA 可能很棘手(认为U2F 有 openssh 补丁),但最简单的方法可能是Yubico 官方网站上描述的方法。

    它基本上是将您的私钥存储在 Yubikey 上并使用 PIN 保护它的方式。它不完全是您所描述的 2FA(但它是您所拥有的和您所知道的),但它进一步提高了安全性(在一些不成功的尝试后 Yubikey 锁定)。

    TL:博士;

    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]
    
    • 2

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve