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 / 问题 / 783798
Accepted
Itai Ganot
Itai Ganot
Asked: 2016-06-15 00:28:08 +0800 CST2016-06-15 00:28:08 +0800 CST 2016-06-15 00:28:08 +0800 CST

如何配置 pam sshd 以允许不同用户/组的不同规则?

  • 772

我正在我工作的公司的出站服务器上配置谷歌双重身份验证。

以下是相关配置 /etc/ssh/sshd_config:

ubuntu@stage-itai-1:~$ egrep -v '^#' /etc/ssh/sshd_config  | sed '/^\s*$/d'
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication yes
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
Match Group gauth
    AuthenticationMethods publickey,keyboard-interactive

/etc/pam.d/sshd:

ubuntu@stage-itai-1:~$ egrep -v '^#' /etc/pam.d/sshd  | sed '/^\s*$/d'
auth required pam_google_authenticator.so nullok
account    required     pam_nologin.so
@include common-account
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_keyinit.so force revoke
@include common-session
session    optional     pam_motd.so  motd=/run/motd.dynamic noupdate
session    optional     pam_motd.so # [1]
session    optional     pam_mail.so standard noenv # [1]
session    required     pam_limits.so
session    required     pam_env.so # [1]
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open
@include common-password

作为“gauth”组成员的用户应该被强制提供公钥和谷歌验证码,这是预期的和有效的。

不是“gauth”组成员的用户应该被强制提供公钥,但实际上他们可以在不提供公钥或密码的情况下连接到机器。

机器上有一个称为“救援”的特殊用户,该用户应该被强制只提供密码,其目的是永远不会被锁定在机器之外,但实际上用户可以在没有密码的情况下连接密码。

我的问题是,我如何执行我的“假定”规则,这意味着:

  • “gauth”组的用户必须同时提供公钥和 Google OTP
  • 不是“gauth”组成员的用户只能通过提供公钥登录。
  • 用户“rescue”应该只能通过提供密码(或同时提供公钥)登录。

怎么做到呢?

编辑#1:

按照 FaCe 的回答,我的配置/etc/ssh/sshd_config如下:

对于整个文件,我已将 PasswordAuthentication 改回“是”,将“ChallengeResponseAuthentication”改回“否”,然后在文件底部添加以下行:

Match Group guath
    PasswordAuthentication no
    ChallengeResponseAuthentication yes
    AuthenticationMethods publickey,keyboard-interactive
Match User rescue
    PasswordAuthentication yes
    ChallengeResponseAuthentication no
    AuthenticationMethods password

重置 ssh 服务后我无法登录,无论我使用哪个用户,我都会收到以下错误:

ssh_exchange_identification: Connection closed by remote host

并且没有任何内容显示在/var/log/auth.log.

任何人都可以对此事有所了解吗?

authentication ssh pam google-authenticator
  • 2 2 个回答
  • 5907 Views

2 个回答

  • Voted
  1. Best Answer
    FaCE
    2016-06-15T00:57:41+08:002016-06-15T00:57:41+08:00

    您需要使用多个匹配组指令:

    Match Group foo
        # blah settings
    Match Group bar
        # blah settings
        ...
    Standard settings
    
    • 2
  2. A.P.
    2016-12-05T02:42:50+08:002016-12-05T02:42:50+08:00
    Match Group guath
        PasswordAuthentication no
        ChallengeResponseAuthentication yes
        AuthenticationMethods publickey,keyboard-interactive
    

    不确定您的 Ubuntu 版本,但在 Debian Jessie 上,ChallengeResponseAuthentication关键字不能是Match块的一部分。根据man sshd_config:

    Only a subset of keywords may be used on the lines following a Match keyword. 
    
    Available keywords are:
                 AcceptEnv, AllowAgentForwarding, AllowGroups, AllowTcpForwarding, AllowUsers, AuthenticationMethods,
                 AuthorizedKeysCommand, AuthorizedKeysCommandUser, AuthorizedKeysFile, AuthorizedPrincipalsFile, Banner,
                 ChrootDirectory, DenyGroups, DenyUsers, ForceCommand, GatewayPorts, GSSAPIAuthentication,
                 HostbasedAuthentication, HostbasedUsesNameFromPacketOnly, KbdInteractiveAuthentication,
                 KerberosAuthentication, MaxAuthTries, MaxSessions, PasswordAuthentication, PermitEmptyPasswords,
                 PermitOpen, PermitRootLogin, PermitTTY, PermitTunnel, PermitUserRC, PubkeyAuthentication, RekeyLimit,
                 RhostsRSAAuthentication, RSAAuthentication, X11DisplayOffset, X11Forwarding and X11UseLocalHost.
    
    • 1

相关问题

  • 如何在使用 RPC over HTTPS 时停止 Outlook 2007 要求提供凭据

  • 针对 Leopard 服务器的 OS X 登录身份验证

  • 允许用户更改其 Active Directory 密码的 Web 界面

  • MOSS 2007 无法使用 ActiveDirectoryMembershipProvider 配置表单身份验证

  • 通过 VPN 更改 Active Directory 密码

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