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 / 问题 / 1073593
Accepted
Hamish Moffatt
Hamish Moffatt
Asked: 2021-08-05 23:28:59 +0800 CST2021-08-05 23:28:59 +0800 CST 2021-08-05 23:28:59 +0800 CST

使用谷歌身份验证器的 SSH 公钥身份验证仍然要求输入密码

  • 772

我正在尝试使用 libpam-google-authenticator 通过 ssh 启用 2FA。并非所有用户都需要启用身份验证器。每个人都使用 ssh 公钥,没有人有密码。我正在运行 Debian buster,并且我还尝试了来自 Bullseye 的 libpam-google-authenticator。

我的问题是,无论我在 PAM 配置中添加什么,没有启用身份验证器的用户永远不会直接登录,而是总是要求输入密码。

我已经安装了 libpam-google-authenticator 并配置了 /etc/ssh/sshd_config :

PasswordAuthentication no
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
PermitEmptyPasswords no

我无法计算出正确的 PAM 配置,因此没有 .google_authenticator 文件的用户仍然可以登录。根据我使用的内容,系统会提示用户输入密码(他们没有密码),或者没有完全允许进入。

在 /etc/pam.d/sshd 我尝试过(像这样Trying to get SSH with public key (no password) + google 身份验证器在 Ubuntu 14.04.1 上工作):

#@include common-auth
auth       required     pam_google_authenticator.so debug nullok

在这种情况下,没有验证器设置的用户会被以下调试拒绝;

Aug 05 15:11:18 <host> sshd(pam_google_authenticator)[746624]: debug: start of google_authenticator for "<user>"
Aug 05 15:11:18 <host> sshd(pam_google_authenticator)[746624]: debug: end of google_authenticator for "<user>" Result: The return value should be ignored by PAM dispatch
Aug 05 15:11:18 <host> sshd[746620]: error: PAM: Permission denied for <user> from <IP>

是否pam_permit需要设置后备案例?

我也尝试过之前和之后的各种组合,auth required但auth sufficient它们@include common-auth都会导致没有验证器的用户被要求输入密码,有时也会要求有验证器的用户输入密码。

有没有人有做这个工作的食谱?

debian pam google-authenticator two-factor
  • 2 2 个回答
  • 1093 Views

2 个回答

  • Voted
  1. Best Answer
    Hamish Moffatt
    2021-08-10T18:52:29+08:002021-08-10T18:52:29+08:00

    这是我的工作配置。有些用户启用了身份验证器,有些则没有,并且只允许使用公钥进行 SSH 登录,从不允许使用密码。

    在 /etc/ssh/sshd_config 中,

    UsePAM yes
    PasswordAuthentication no
    ChallengeResponseAuthentication yes
    AuthenticationMethods publickey,keyboard-interactive
    PermitEmptyPasswords no
    

    在 /etc/pam.d/sshd 中,

    # Standard Un*x authentication.
    #@include common-auth
    
    # Require authenticator, if not configured then allow
    auth    required    pam_google_authenticator.so debug nullok
    auth    required    pam_permit.so
    

    @include comon-auth必须禁用,因为它包含我不想使用的 pam_unix。然后,您需要pam_permit使没有身份验证器的用户身份验证成功(为此pam_google_authenticator返回忽略而不是通过)。

    这仍然不允许 root 使用 ssh 密钥登录;sshd 日志

    sshd[1244501]: fatal: Internal error: PAM auth succeeded when it should have failed
    

    这在Google Authenticator PAM 上讨论了 SSH 阻止 root login without 2FA。

    如上所述,我认为使用 SSH 配置为某些组强制执行 2FA 实际上更好,正如@zoredache 建议的那样。这很容易让您将某些 IP 列入白名单,因为它们也不需要 2FA。在这种情况下, sshd_config 例如说

    UsePAM yes
    PasswordAuthentication no
    ChallengeResponseAuthentication yes
    #AuthenticationMethods any # default
    PermitEmptyPasswords no
    
    Match Group adm Address *,!172.16.1.0/24
        AuthenticationMethods publickey,keyboard-interactive
    

    和 /etc/pam.d/ssh 说

     Standard Un*x authentication.
    #@include common-auth
    
    # Require authenticator; SSH should not allow any user in who doesn't have it
    auth       sufficient   pam_google_authenticator.so debug nullok
    auth       requisite    pam_deny.so
    
    • 2
  2. Zoredache
    2021-08-05T23:45:21+08:002021-08-05T23:45:21+08:00

    我认为您不需要或不想评论@include common-auth. 或者至少我没有,它似乎工作正常。但我仍然主要是在测试这个。

    有没有人有做这个工作的食谱?

    没有时间为您将其翻译成 shell 脚本,但这是一个似乎对我有用的 ansible playbook 的摘录。我怀疑即使您不使用 ansible,您也应该能够跟随它在做什么。

    - hosts: linux_systems
      tasks:
    
      - name: Add group 'totp'
        group:
          name: totp
          state: present
          system: yes
    
      - name: Create directory for totp secrets
        file:
          state: directory
          path: /var/lib/google-authenticator
          owner: "0"
          group: "0"
          mode: "0700"
    
      - name: install libpam-google-authenticator
        apt:
          update_cache: yes
          cache_valid_time: '{{ apt_cache_valid_time | default(7200) }}'
          state: present
          name:
          - libpam-google-authenticator
    
      - name: Create secret for 'example-user'
        args:
          creates: /var/lib/google-authenticator/example-user
        shell: |
          TOTP_USER=example-user; \
          google-authenticator \
            --force --quiet \
            --emergency-codes=10 \
            --time-based \
            --qr-mode=none \
            --allow-reuse \
            --window-size=3 \
            --rate-limit=4 --rate-time=30 \
            --secret=/var/lib/google-authenticator/${TOTP_USER}
    
      - name: update pam
        lineinfile:
          insertafter: '^@include common-password'
          path: /etc/pam.d/login
          line: 'auth required pam_google_authenticator.so nullok user=root secret=/var/lib/google-authenticator/${USER}'
    
      - name: update pam
        lineinfile:
          insertafter: '^@include common-password'
          path: /etc/pam.d/sshd
          line: 'auth required pam_google_authenticator.so nullok user=root secret=/var/lib/google-authenticator/${USER}'
    
      - name: update sshd ChallengeResponseAuthentication
        notify: Restart sshd
        lineinfile:
          path: /etc/ssh/sshd_config
          regexp: '^ChallengeResponseAuthentication .*'
          line: 'ChallengeResponseAuthentication yes'
    
      handlers:
    
      - name: Restart sshd
        service:
          name: sshd
          state: restarted
    
    • 0

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

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