sshd_config中的意外匹配行为

托马斯·奥克肯(Thomas Okken)

我正在尝试在我的服务器中配置以下限制sshd_config

  1. 具有本地IP地址的用户没有限制
  2. 组中具有非本地IP地址的用户sftp被允许在chroot监狱中使用sftp
  3. 不在sftp中的具有非本地IP地址的用户将不允许执行任何操作。

这是我想出的:

Match Address 10.0.0.0/24,172.16.0.0/20,192.168.0.0/16
        X11Forwarding yes

Match Address *,!10.0.0.0/24,!172.16.0.0/20,!192.168.0.0/16 Group sftp
        X11Forwarding no
        AllowTcpForwarding no
        ChrootDirectory %h
        ForceCommand internal-sftp

Match Address *,!10.0.0.0/24,!172.16.0.0/20,!192.168.0.0/16 Group *,!sftp
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand /sbin/nologin

问题是:当我尝试从内部地址登录时,以非sftp用户身份被拒绝;第三次比赛触发。

根据sshd_config联机帮助页的说明,仅当满足所有匹配条件时,才满足Match的要求,但在我的情况下,不满足第一个条件(我来自IP地址为172.16.0.0/20的计算机)第二个是(我不在sftp组中)。

sshd_config手册页错了吗?有可能做我想做的事吗?

更新:在@steve的建议下,我在调试模式下运行了sshd,并得到了以下信息:

debug1: userauth-request for user root service ssh-connection method none
debug1: attempt 0 failures 0
debug1: connection from 172.19.187.49 matched 'Address *,!10.0.0.0/24,!172.16.0.0/20,!192.168.0.0/16' at line 144
debug1: user root does not match group list sftp at line 144
debug1: connection from 172.19.187.49 matched 'Address *,!10.0.0.0/24,!172.16.0.0/20,!192.168.0.0/16' at line 150
debug1: user root matched group list *,!sftp at line 150
debug1: PAM: initializing for "root"

no-internal-adress子句是匹配的;此外,调试日志中未提及第一个匹配项,这似乎很奇怪。

更新:

正如@Gilles指出的那样,我上面显示的地址规范不正确。我应该使用的是10.0.0.0/8,而不是10.0.0.0/24和172.16.0.0/12,而不是172.16.0.0/20。我是从32开始而不是从0开始计数掩码位。

使用更正的地址,配置即可工作。谢谢吉勒斯和乌列尔!

(我还将最后一行中的/ sbin / nologin更改为/ bin / false;前者会导致来自sftp:的奇怪错误消息Received message too long 1416128883。)

乌列尔

您的netmaks是不正确的。如果要包括专用网络,则应使用:

10.0.0.0/8,172.16.0.0/12,192.168.0.0/16

这可能就是为什么您不匹配而不是ssh错误的原因。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

匹配“ sshd_config”中的多个用户

来自分类Dev

匹配sshd_config中的用户放置

来自分类Dev

sshd_config中的Uselogin

来自分类Dev

无法使sshd_config匹配用户正常工作

来自分类Dev

sshd_config中的chroot指令无法排除用户

来自分类Dev

sshd_config中的X11DisplayOffset

来自分类Dev

使用 ansible playbook 修改 sshd_config 中的 AllowGroups

来自分类Dev

如何配置sshd_config

来自分类Dev

后备sshd_config脚本

来自分类Dev

保留sshd_config设置

来自分类Dev

使用 cloud init config 更改 /etc/ssh/sshd_config 中的默认值

来自分类Dev

使用 cloud init config 更改 /etc/ssh/sshd_config 中的默认值

来自分类Dev

使用sshd_config限制root登录?

来自分类Dev

OS X忽略sshd_config

来自分类Dev

sshd_config 选项:`PermitTunnel` 与 `AllowTcpForwarding`

来自分类Dev

谷歌云恢复 sshd_config

来自分类Dev

Authorized_keys中的选项与sshd_config中的选项之间的关系?

来自分类Dev

sshd_config文件中的“无密码”是什么意思?

来自分类Dev

在不重启服务器的情况下更改sshd_config文件中的文件

来自分类Dev

在cygwin中设置sshd_config以进行AES加密文件传输

来自分类Dev

为什么TZ通常不在/ etc / ssh / sshd_config的AcceptEnv中列出

来自分类Dev

sshd_config中的`ServerAliveInterval`和`ClientAliveInterval`选项到底有什么作用?

来自分类Dev

有人可以在/ etc / ssh / sshd_config文件中解释“ PasswordAuthentication”吗?

来自分类Dev

尽管sshd_config中的选项“ PermitRootLogin yes”仍然无法使用根ssh

来自分类Dev

即使/ etc / ssh / sshd_config中的“ PasswordAuthentication no”也可以通过SFTP使用密码身份验证

来自分类Dev

在 Windows Subsytem for Linux 中访问 Python 解释器,在 sshd_config 中出错?

来自分类Dev

如何在 sshd_config 中没有 PubkeyAuthentication 时排除某人

来自分类Dev

SaltStack:SLS sshd中的必需声明文件/ etc / ssh / sshd_config不形成为单个密钥字典

来自分类Dev

SaltStack:SLS sshd中的必需声明文件/ etc / ssh / sshd_config不形成为单个密钥字典

Related 相关文章

  1. 1

    匹配“ sshd_config”中的多个用户

  2. 2

    匹配sshd_config中的用户放置

  3. 3

    sshd_config中的Uselogin

  4. 4

    无法使sshd_config匹配用户正常工作

  5. 5

    sshd_config中的chroot指令无法排除用户

  6. 6

    sshd_config中的X11DisplayOffset

  7. 7

    使用 ansible playbook 修改 sshd_config 中的 AllowGroups

  8. 8

    如何配置sshd_config

  9. 9

    后备sshd_config脚本

  10. 10

    保留sshd_config设置

  11. 11

    使用 cloud init config 更改 /etc/ssh/sshd_config 中的默认值

  12. 12

    使用 cloud init config 更改 /etc/ssh/sshd_config 中的默认值

  13. 13

    使用sshd_config限制root登录?

  14. 14

    OS X忽略sshd_config

  15. 15

    sshd_config 选项:`PermitTunnel` 与 `AllowTcpForwarding`

  16. 16

    谷歌云恢复 sshd_config

  17. 17

    Authorized_keys中的选项与sshd_config中的选项之间的关系?

  18. 18

    sshd_config文件中的“无密码”是什么意思?

  19. 19

    在不重启服务器的情况下更改sshd_config文件中的文件

  20. 20

    在cygwin中设置sshd_config以进行AES加密文件传输

  21. 21

    为什么TZ通常不在/ etc / ssh / sshd_config的AcceptEnv中列出

  22. 22

    sshd_config中的`ServerAliveInterval`和`ClientAliveInterval`选项到底有什么作用?

  23. 23

    有人可以在/ etc / ssh / sshd_config文件中解释“ PasswordAuthentication”吗?

  24. 24

    尽管sshd_config中的选项“ PermitRootLogin yes”仍然无法使用根ssh

  25. 25

    即使/ etc / ssh / sshd_config中的“ PasswordAuthentication no”也可以通过SFTP使用密码身份验证

  26. 26

    在 Windows Subsytem for Linux 中访问 Python 解释器,在 sshd_config 中出错?

  27. 27

    如何在 sshd_config 中没有 PubkeyAuthentication 时排除某人

  28. 28

    SaltStack:SLS sshd中的必需声明文件/ etc / ssh / sshd_config不形成为单个密钥字典

  29. 29

    SaltStack:SLS sshd中的必需声明文件/ etc / ssh / sshd_config不形成为单个密钥字典

热门标签

归档