Zero-Key Browser SSH to a Mac mini via Cloudflare Tunnel
Following up on
reaching a home lab with pure OpenSSH
: a
reverse SSH tunnel via a VPS jump box gives you end-to-end encryption and full
OpenSSH features, but it still requires a VPS, outbound SSH from corp-laptop,
and an encrypted personal SSH private key sitting on corp-laptop.
When you want zero personal SSH keys on corp-laptop (or pi), or only
HTTPS/443 is allowed out, Cloudflare Tunnel (cloudflared) running on pi can
route a Cloudflare Zero Trust Access application straight over the home LAN to a
Mac mini (mini:22)—rendered directly in a browser terminal and authenticated
with hardware Passkeys and Short-lived SSH Certificates.
Reverse SSH Tunnel vs. Cloudflare Tunnel
| Dimension | Reverse SSH Tunnel (VPS) | Cloudflare Tunnel (Browser SSH) |
|---|---|---|
| Infrastructure | VPS + stock OpenSSH / systemd |
Free tier + domain on CF DNS + cloudflared |
| Client setup | Native ssh + encrypted personal key |
Browser only (HTTPS/443); zero keys on client |
| Capabilities | Full ssh, scp, rsync, -L/-D |
Interactive xterm.js shell only |
| Trust boundary | End-to-end SSH; no third party | CF Edge decrypts browser I/O & signs certs |
| Reconnect / uptime | Single VPS (~90s stale-port window) | 4 redundant QUIC/HTTP2 conns across 2 PoPs |
Trade-offs of the Cloudflare Tunnel path:
- Pros: zero SSH private keys on
corp-laptoporpi, works over plain HTTPS/443 without installingcloudflaredon the client, hardware Passkey auth via Cloudflare Access, and shares the samepitunnel with other home services (e.g., a family webcam). - Cons: Cloudflare sits in the auth boundary (mitigated by scoping the CA to a
non-admin user
cfuserfrompi’s IP) and decrypts terminal I/O at its edge to render the browser UI (every hop on the wire is still encrypted—HTTPS/WSS to the browser, QUIC/TLS + SSH topi, and SSH on the LAN tomini—just not end-to-end encrypted through Cloudflare); browserxterm.jslacksscp,rsync, and port forwarding.
Architecture
browser (Passkey) --> Cloudflare Edge (Access + SSH CA)
| (cloudflared tunnel)
v
pi (10.0.0.6) --(LAN :22)--> mini (10.0.0.7, user: cfuser)
- Direct LAN routing from
cloudflared(pi→mini:22): avoids usingpias an SSH jump hop and eliminates any SSH private key onpi. - Passkeys + Short-lived SSH Certificates: authentication requires a hardware
security key / Passkey at Cloudflare Access, which mints an ephemeral SSH
certificate so zero personal SSH keys live on
corp-laptop. - Least-privilege blast-radius isolation:
TrustedUserCAKeysis scoped strictly to a dedicated Standard (non-admin) macOS user (cfuser) and connections frompi’s LAN IP (10.0.0.6), keeping the macOS admin account unreachable by Cloudflare’s CA.
1. Router, cloudflared on pi, and Cloudflare Zero Trust
- Home router: reserve static DHCP IPs for
pi(e.g.,10.0.0.6) andmini(e.g.,10.0.0.7) so the tunnel target andsshdAddressmatch never drift. - Mac mini power: disable automatic sleep so
pican always reach port22. - On
pi: installcloudflaredfrom Cloudflare’s APT repo and register itssystemdservice (sudo cloudflared service install <TUNNEL_TOKEN>). - Cloudflare Zero Trust: follow Cloudflare’s
Browser-rendered SSH terminal
guide to wire up the Access application, Short-lived SSH Certificate, and
tunnel route, watching out for a few pitfalls:
- Create the Self-hosted Access Application before adding the tunnel route
(leaving Path blank) so
mini:22is never exposed unauthenticated. - Restrict the application to Passkeys only (uncheck One-time PIN) so login requires a hardware key or Passkey instead of email OTP.
- The allowed email prefix must match the non-admin macOS username
(
[email protected]→cfuser): browser SSH always logs in as the prefix before@and cannot remap viaAuthorizedPrincipalsFile(use an alternate email alias if needed). - Point the tunnel’s
SSHroute atmini’s static LAN IP (10.0.0.7:22), notlocalhost:22, sincecloudflaredruns onpi.
- Create the Self-hosted Access Application before adding the tunnel route
(leaving Path blank) so
2. Non-Admin User & Remote Login on Mac mini
- Create a Standard (non-admin) macOS user matching the Access email prefix
(
cfuser) so Cloudflare’s CA can never access the admin user orsudo. - Enable Remote Login (
System Settings -> General -> Sharing -> Remote Login) and addcfuserto thecom.apple.access_sshallowlist. Without this, macOS PAM (pam_sacl) accepts the key or certificate and immediately drops the connection withConnection closed:
sudo dseditgroup -o edit -a cfuser -t user com.apple.access_ssh
3. Mac mini sshd Hardening & Scoped Cloudflare CA
macOS upgrades can overwrite /etc/ssh/sshd_config, so keep all custom rules in
/etc/ssh/sshd_config.d/ (included at the top of /etc/ssh/sshd_config).
- Base hardening (
/etc/ssh/sshd_config.d/00-hardening.conf): enforce key/certificate-only auth and restrict SSH logins to home LAN + loopback:
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PubkeyAuthentication yes
AuthenticationMethods publickey
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowUsers *@10.0.0.0/24 *@127.0.0.1 *@::1
EOF
sudo chmod 644 /etc/ssh/sshd_config.d/00-hardening.conf
- Save Cloudflare’s SSH CA public key (
/etc/ssh/cloudflare-ca.pub):
sudo tee /etc/ssh/cloudflare-ca.pub >/dev/null <<'EOF'
<CLOUDFLARE_SSH_CA_PUBLIC_KEY>
EOF
sudo chown root:wheel /etc/ssh/cloudflare-ca.pub
sudo chmod 400 /etc/ssh/cloudflare-ca.pub
- Scope CA trust strictly to
cfuserfrompi’s LAN IP (/etc/ssh/sshd_config.d/99-cf-access.conf):
sudo tee /etc/ssh/sshd_config.d/99-cf-access.conf >/dev/null <<'EOF'
Match User cfuser Address 10.0.0.6
PubkeyAuthentication yes
TrustedUserCAKeys /etc/ssh/cloudflare-ca.pub
EOF
sudo chmod 644 /etc/ssh/sshd_config.d/99-cf-access.conf
4. Verification & Troubleshooting
Validate syntax and confirm TrustedUserCAKeys only applies to cfuser from
pi’s LAN IP:
sudo /usr/sbin/sshd -t
# Expected: trustedusercakeys /etc/ssh/cloudflare-ca.pub
sudo /usr/sbin/sshd -T -C "user=cfuser,addr=10.0.0.6" | grep trustedusercakeys
# Expected: trustedusercakeys none (admin user must never trust the CA)
sudo /usr/sbin/sshd -T -C "user=<ADMIN_USER>,addr=10.0.0.6" | grep trustedusercakeys
# Expected: trustedusercakeys none (other LAN IPs must not trust the CA)
sudo /usr/sbin/sshd -T -C "user=cfuser,addr=10.0.0.1" | grep trustedusercakeys
If login closes immediately after authentication, inspect macOS sshd logs:
log show --predicate 'process == "sshd" OR process == "sshd-session"' --last 5m