Skip to content
Search AlmaLinux

    Browse this documentation

    AlmaLinux 10: sshd Match blocks — one config file, many answers

    An AlmaLinux 10.2 Server VM running OpenSSH_9.9p1.

    Method: read the global effective config, add a Match block scoped to a single source address, query two different sources with sshd -T -C, then clean up. Screenshot: public/evidence/sshd/alma-match.png.

    $ sshd -T -C user=labuser,host=localhost,addr=192.168.2.241 | grep -E '^(maxauthtries|x11forwarding|passwordauthentication)'
    maxauthtries 6
    passwordauthentication yes
    x11forwarding yes

    sshd -T prints the parsed configuration rather than the file text, which makes it far more trustworthy than reading sshd_config by eye.

    /etc/ssh/sshd_config.d/50-lab-match.conf
    Match Address 192.168.2.240
    MaxAuthTries 2
    X11Forwarding no
    $ sshd -t && echo "config OK"
    config OK

    sshd -t only checks syntax — it never tells you whether the Match applies. That separation is the whole point of the next step.

    $ sshd -T -C user=labuser,host=localhost,addr=192.168.2.240 | grep -E '^(maxauthtries|x11forwarding)'
    maxauthtries 2
    x11forwarding no
    $ sshd -T -C user=labuser,host=localhost,addr=192.168.2.241 | grep -E '^(maxauthtries|x11forwarding)'
    maxauthtries 6
    x11forwarding yes

    -C means “pretend this connection comes from here”: user=, host=, addr=. It is the only direct way to verify Match behaviour; do this instead of trial-and-error logins.

    AlmaLinux 10.2: a Match block and per-connection effective settings

    $ ls /etc/ssh/sshd_config.d/

    EL10’s sshd_config starts with Include /etc/ssh/sshd_config.d/*.conf, loaded in filename order. Two practical rules:

    1. Use numeric prefixes (50- before 99-); later files override earlier values;
    2. Everything after a Match belongs to that block — never put global directives after a Match in the same file, or they get absorbed.
    GoalPatternCaveat
    Password auth only from the LANMatch Address 192.168.2.0/24 + PasswordAuthentication yesDisable it globally first
    No root login from anywhereMatch Address 0.0.0.0/0 + PermitRootLogin noOrder-sensitive against global clauses
    Restrict forwarding for one userMatch User deploy + AllowTcpForwarding noA missing user fails silently

    Key limit: Match changes parameter values; it does not grant access and does not override other layers such as firewalld or PAM.

    • Editing a drop-in without reloading: systemctl reload sshd is required; sshd -t only validates;
    • Verifying Match with plain sshd -T: it shows global values only;
    • Typos in conditions: sshd -t catches syntax, not a wrong subnet — compare with -C;
    • Global directives after Match: they silently become block-local, which looks like “some settings only work for some people”.
    Terminal window
    sudo tee /etc/ssh/sshd_config.d/60-lab.conf >/dev/null <<'EOF'
    Match Address 192.168.2.0/24
    MaxAuthTries 3
    EOF
    sudo sshd -t
    sudo sshd -T -C user=labuser,host=localhost,addr=192.168.2.10 | grep maxauthtries
    sudo sshd -T -C user=labuser,host=localhost,addr=10.0.0.10 | grep maxauthtries
    sudo rm /etc/ssh/sshd_config.d/60-lab.conf

    Checks:

    1. The in-subnet address reports 3, the outside one keeps 6;
    2. sshd -t is silent on success;
    3. After removal both report 6 again;
    4. No reload was needed — -T reads the config without touching live sessions.

    常见问题

    Can Match blocks nest?

    No. A Match block runs until the end of the file or the next Match; there is no nesting.

    Why does sshd -T not show my Match settings?

    It prints the global context. Use sshd -T -C user=...,host=...,addr=... to evaluate a specific connection.

    Reload or restart after editing?

    Reload (systemctl reload sshd) applies the config without dropping established sessions; restart does drop them.