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 / 问题 / 870464
Accepted
MarkHelms
MarkHelms
Asked: 2017-08-26 06:59:10 +0800 CST2017-08-26 06:59:10 +0800 CST 2017-08-26 06:59:10 +0800 CST

允许从某些 IP 地址对某些组进行 ssh 登录,从其他地址拒绝

  • 772

操作系统:CentOS 6.5 SSH v5.3

目标:

  • 来自多个主机的 PubKeyAuthentication 允许 root 访问。

  • “group1”的用户可以使用他们提供的任何东西登录:PubKey、Password、GSSAPI、KerberosPassword;但它们只能从一个特定的 IP 到达:192.168.1.10

状态:root 访问权限已通过 中的多个from=""-entries定义~/.ssh/authorized_keys,并且按预期工作。

问题:group1 的用户可以从 192.168.1.10 或从其他地方到达;或完全锁定(使用早期测试的配置)。

我尝试了几种变体,但无济于事。

/etc/pam.d/sshd实际上看起来像:

    auth        sufficient    pam_unix.so nullok try_first_pass
    auth        requisite     pam_succeed_if.so uid >= 500 quiet

目前我在sshd_config:

    PermitRootLogin without-password
    PasswordAuthentication no
    KerberosAuthentication no
    GSSAPIAuthentication no
    UsePAM yes

    AllowGroups root group1

    Match Group [email protected]
        KerberosAuthentication yes
        PasswordAuthentication yes
        GSSAPIAuthentication yes
        PubKeyAuthentication yes
    Match Group root
        PubKeyAuthentication yes

有什么建议吗?

ssh
  • 1 1 个回答
  • 2575 Views

1 个回答

  • Voted
  1. Best Answer
    MarkHelms
    2017-08-27T05:49:53+08:002017-08-27T05:49:53+08:00

    我找到了一个可行的解决方案。sshd 调试模式 ( /usr/sbin/sshd -ddd) 表示缺少链接:

        debug1: connection from 192.168.1.111 matched 'Address *'
        debug3: match found
        [...]
        Accepted **keyboard-interactive/pam** for xxx from \ 
               192.168.1.111 port 54282 ssh2
    

    如您所见,登录名匹配了正确的块;但由于UsePAM yes PAM显然否决了Match Address *块中的“否”条目;见手册:

        UsePAM  Enables the Pluggable Authentication Module interface. 
                If set to “yes” this will enable PAM authentication using
                [...] PasswordAuthentication
    

    最终配置如下所示:

        PermitRootLogin without-password
        PasswordAuthentication no
        KerberosAuthentication no
        GSSAPIAuthentication no
    
        UsePAM yes
    
        AllowGroups root group1
    
        Match Address 192.168.1.10
          KerberosAuthentication yes
          PasswordAuthentication yes
          GSSAPIAuthentication yes
          PubKeyAuthentication yes
          KbdInteractiveAuthentication yes
    
        Match Group root
          PubKeyAuthentication yes
    
        Match Address *
          KerberosAuthentication no
          PasswordAuthentication no
          GSSAPIAuthentication no
          PubKeyAuthentication no
          KbdInteractiveAuthentication no
    

    只有在添加KbdInteractiveAuthentication no了 PAM 密码功能后,此块才被禁用,来自任何地方的用户现在都被成功拒绝。

    • 0

相关问题

  • 如何最好地设置 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