brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a Match Address block in sshd_config allows passwords only from your LAN

Network and access
~/tips/tip-sshd-match-address

Match Address 192.0.2.0/24

Use different SSH server rules for logins from your own network and from outside.

I want key-only logins from the internet, but on the home network a password is a fine fallback. sshd_config can do both with a Match block.

Set the strict default in the main part of the file, and loosen it for one range at the bottom:

PasswordAuthentication no

Match Address 192.0.2.0/24
    PasswordAuthentication yes

Everything after Match applies only when the condition fits, until the next Match line or the end of the file. That is why Match blocks go at the end. A normal option placed below a Match block silently belongs to that block.

You can match on User, Group, Host, LocalPort and a few more, and combine them. To see the result for one case, ask sshd directly:

sudo sshd -T -C addr=192.0.2.50,user=alice,host=laptop | grep -i passwordauthentication

Not every option is allowed inside a Match block. The man page lists the ones that are, and sshd -t complains if you use another.

One caveat about the address: behind a port forward on your router, or a reverse proxy, every connection may appear to come from the router’s own LAN address. Then the whole internet gets the LAN rules. Check the source address in the log before you trust this.

Further reading: sshd_config man page, sshd man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link