Zero-Key Browser SSH to a Mac mini via Cloudflare Tunnel

style-newspaper len:6542 crease:32% color:4 rot:-3

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-laptop or pi, works over plain HTTPS/443 without installing cloudflared on the client, hardware Passkey auth via Cloudflare Access, and shares the same pi tunnel 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 cfuser from pi’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 to pi, and SSH on the LAN to mini—just not end-to-end encrypted through Cloudflare); browser xterm.js lacks scp, 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)
  1. Direct LAN routing from cloudflared (pi → mini:22): avoids using pi as an SSH jump hop and eliminates any SSH private key on pi.
  2. 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.
  3. Least-privilege blast-radius isolation: TrustedUserCAKeys is scoped strictly to a dedicated Standard (non-admin) macOS user (cfuser) and connections from pi’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) and mini (e.g., 10.0.0.7) so the tunnel target and sshd Address match never drift.
  • Mac mini power: disable automatic sleep so pi can always reach port 22.
  • On pi: install cloudflared from Cloudflare’s APT repo and register its systemd service (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:22 is 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 via AuthorizedPrincipalsFile (use an alternate email alias if needed).
    • Point the tunnel’s SSH route at mini’s static LAN IP (10.0.0.7:22), not localhost:22, since cloudflared runs on pi.

2. Non-Admin User & Remote Login on Mac mini

  1. Create a Standard (non-admin) macOS user matching the Access email prefix (cfuser) so Cloudflare’s CA can never access the admin user or sudo.
  2. Enable Remote Login (System Settings -> General -> Sharing -> Remote Login) and add cfuser to the com.apple.access_ssh allowlist. Without this, macOS PAM (pam_sacl) accepts the key or certificate and immediately drops the connection with Connection 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).

  1. 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
  1. 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
  1. Scope CA trust strictly to cfuser from pi’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

Zero-Key Browser SSH to a Mac mini via Cloudflare Tunnel

style-newspaper len:6542 crease:32% color:4 rot:-3
Dec 2, 2026

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-laptop or pi, works over plain HTTPS/443 without installing cloudflared on the client, hardware Passkey auth via Cloudflare Access, and shares the same pi tunnel 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 cfuser from pi’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 to pi, and SSH on the LAN to mini—just not end-to-end encrypted through Cloudflare); browser xterm.js lacks scp, 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)
  1. Direct LAN routing from cloudflared (pi → mini:22): avoids using pi as an SSH jump hop and eliminates any SSH private key on pi.
  2. 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.
  3. Least-privilege blast-radius isolation: TrustedUserCAKeys is scoped strictly to a dedicated Standard (non-admin) macOS user (cfuser) and connections from pi’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) and mini (e.g., 10.0.0.7) so the tunnel target and sshd Address match never drift.
  • Mac mini power: disable automatic sleep so pi can always reach port 22.
  • On pi: install cloudflared from Cloudflare’s APT repo and register its systemd service (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:22 is 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 via AuthorizedPrincipalsFile (use an alternate email alias if needed).
    • Point the tunnel’s SSH route at mini’s static LAN IP (10.0.0.7:22), not localhost:22, since cloudflared runs on pi.

2. Non-Admin User & Remote Login on Mac mini

  1. Create a Standard (non-admin) macOS user matching the Access email prefix (cfuser) so Cloudflare’s CA can never access the admin user or sudo.
  2. Enable Remote Login (System Settings -> General -> Sharing -> Remote Login) and add cfuser to the com.apple.access_ssh allowlist. Without this, macOS PAM (pam_sacl) accepts the key or certificate and immediately drops the connection with Connection 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).

  1. 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
  1. 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
  1. Scope CA trust strictly to cfuser from pi’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

Reaching a Home Lab from a Locked-Down Work Laptop with Pure OpenSSH

style-newspaper len:7023 crease:78% color:3 rot:2

The default answers for reaching a home server behind ISP NAT are Tailscale or Cloudflare Tunnel (cloudflared). Both are great—until you hit a common set of constraints:

  • Home LAN (behind NAT): An always-on Raspberry Pi (pi) and a Mac mini (mini).
  • Tiny public VPS (vps): Too small for extra VPN daemons, and also a personal dev box that pushes to personal GitHub repos.
  • Locked-down work laptop (corp-laptop): Cannot install VPN clients, outbound SSH is allowed, corporate keys live dynamically in $SSH_AUTH_SOCK, and corporate keys must never be offered or forwarded to the VPS or the internet.

Plain OpenSSH solves all of it with a few megabytes of RAM, end-to-end encryption, zero third-party control planes, and strict separation between corporate and personal keys. Both server setup scripts—setup-tunnel.sh and persist-tunnel.sh —are hosted right alongside this note; for a zero-key browser-only alternative that needs no VPS and no outbound SSH, see the companion Cloudflare Tunnel browser SSH setup.

Why Pure OpenSSH?

Criterion Pure OpenSSH (Reverse Tunnel + ProxyJump) Tailscale Cloudflare Tunnel (Browser SSH)
Corp laptop Outbound SSH + encrypted personal key Blocked (VPN client) Browser only (HTTPS/443); zero keys
Extra software None (sshd + systemd) Daemon on every node cloudflared + domain + Zero Trust
Trust boundary End-to-end (corp-laptop → target) End-to-end WireGuard CF Edge decrypts browser I/O & signs CA
VPS RAM footprint ~few MB ~30–60+ MB N/A (runs on pi)
Capabilities Full ssh, scp, rsync, -L/-D Built-in (full L3) Interactive xterm.js shell only

Tailscale is still great for mobile devices (e.g., viewing a Pi webcam from a phone), and Cloudflare Tunnel is a strong fallback when you want zero personal keys on corp-laptop. Keeping OpenSSH for daily laptop access gives you native terminal ergonomics and full port forwarding without ever putting the VPS on your tailnet.

Architecture

corp-laptop --(SSH #1)--> vps <--(reverse tunnel :2222)-- pi --(LAN :22)--> mini
     |                                                    ^                  ^
     +----------------(SSH #2, end-to-end)----------------+                  |
     +----------------(SSH #3, end-to-end)-----------------------------------+
  1. Persistent reverse tunnel (pi → vps): pi dials out to vps and binds its SSH port strictly to loopback (127.0.0.1:2222) under a locked-down /bin/false user—nothing new is exposed publicly.
  2. Chained ProxyJump (corp-laptop → vps → pi → mini): Every hop authenticates end-to-end from corp-laptop. No personal private keys live on vps or pi, and ForwardAgent stays off for both.
  3. Isolated personal ssh-agent (~/.ssh/agent.sock): OpenSSH cannot filter dynamically loaded corporate keys per host inside a shared agent. A dedicated, unexported personal socket leaves $SSH_AUTH_SOCK untouched while safely enabling ForwardAgent ~/.ssh/agent.sock to vps for personal GitHub pushes.

1. Reverse Tunnel (pi → vps)

Both scripts assume Debian 12+ or Ubuntu 22.04+. First, generate a dedicated passphrase-free ed25519 key on pi solely for unattended tunnel reconnects:

ssh-keygen -t ed25519 -N "" -C "pi-reverse-tunnel" -f ~/.ssh/id_ed25519_vps_tunnel

On vps, fetch and run setup-tunnel.sh with the Pi’s public key (either as a file argument or piped on stdin):

curl -fLO https://joyus.org/2026/lightweight-ssh-homelab/setup-tunnel.sh
chmod +x setup-tunnel.sh
cat id_ed25519_vps_tunnel.pub | sudo ./setup-tunnel.sh

It creates a /bin/false tunnel user, installs a scoped Match User tunnel drop-in at /etc/ssh/sshd_config.d/99-reverse-tunnel-tunnel.conf, validates with sshd -t (rolling back on error), reloads sshd, and verifies the effective config via sshd -T -C user=tunnel. A few details matter:

  • AllowTcpForwarding remote, GatewayPorts no, and PermitListen localhost:* 127.0.0.1:* [::1]:* restrict forwards strictly to loopback. localhost:* is required because OpenSSH sends localhost on the wire for -R 2222:127.0.0.1:22; allowing only 127.0.0.1:* rejects it.
  • ClientAliveInterval 30 / ClientAliveCountMax 3 scoped inside Match User tunnel clears stale tunnels within ~90s after ISP drops without affecting normal sessions.
  • Keep AllowTcpForwarding yes (the default) for your normal users on vps and pi so ProxyJump (ssh -W) works.

On pi, skip autossh and let systemd + OpenSSH handle reconnects via persist-tunnel.sh , which auto-detects pi’s local sshd port and installs reverse-ssh-tunnel.service:

curl -fLO https://joyus.org/2026/lightweight-ssh-homelab/persist-tunnel.sh
chmod +x persist-tunnel.sh
sudo ./persist-tunnel.sh <VPS_IP> 2222

Verify on vps that port 2222 is listening on loopback only:

ss -tln | grep ':2222\b'
# Expected: LISTEN ... 127.0.0.1:2222 0.0.0.0:*

The critical unit options in reverse-ssh-tunnel.service:

  • -F /dev/null + IdentitiesOnly=yes + IdentityFile=... isolate the daemon from your personal ~/.ssh/config.
  • ExitOnForwardFailure=yes forces an immediate exit (and 10s systemd retry) if vps briefly still holds port 2222 from a dead connection.
  • StartLimitIntervalSec=0 prevents systemd from giving up during multi-hour ISP outages, and BatchMode=yes + StrictHostKeyChecking=accept-new avoids interactive hangs while pinning the VPS host key on first connect.

2. Isolated ssh-agent and ~/.ssh/config

On corp-laptop, never overwrite global $SSH_AUTH_SOCK. Instead, start a dedicated personal agent at ~/.ssh/agent.sock in your shell rc without exporting it (see __setup_ssh_agent in zsh/zshrc and bash/bashrc ). There is no passphrase prompt on terminal startup—OpenSSH unlocks the key lazily on first use via AddKeysToAgent, and modern ed25519 private keys embed their public key unencrypted so no sibling .pub file is needed.

Then adapt config.sample into ~/.ssh/config (chmod 600 ~/.ssh/config): Host vps sets ForwardAgent ~/.ssh/agent.sock; Host pi targets 127.0.0.1:2222 via ProxyJump vps with HostKeyAlias pi; Host mini sets ProxyJump pi; a shared Host vps pi mini github.com block pins IdentityAgent ~/.ssh/agent.sock, IdentityFile ~/.ssh/%u.key, IdentitiesOnly yes, and AddKeysToAgent 10h; and corporate hosts sit above Host *.

Three Subtle OpenSSH Gotchas

  1. Never pass -A (ssh -A vps): CLI flags override ~/.ssh/config. -A sets ForwardAgent yes, dropping ~/.ssh/agent.sock and silently forwarding your corporate $SSH_AUTH_SOCK.
  2. Use HostKeyAlias pi for tunneled targets: Avoids [127.0.0.1]:2222 collisions in ~/.ssh/known_hosts with other port forwards.
  3. Never put corporate IdentityFile lines in Host *: Unlike IdentityAgent or ForwardAgent (first-match-wins), IdentityFile accumulates across every matching block.

3. Day-to-Day Usage

Once wired up, every host and tunnel is one command from corp-laptop:

ssh vps                                 # Dev session (personal GitHub via isolated agent)
ssh pi                                  # corp-laptop -> vps -> pi
ssh mini                                # corp-laptop -> vps -> pi -> mini
ssh -N -L 5900:localhost:5900 mini      # Mac mini Screen Sharing -> vnc://localhost:5900
ssh -D 1080 pi                          # Ad-hoc SOCKS5 proxy into home LAN

Sometimes the boring tool sitting in /usr/bin/ssh for 25 years is still the cleanest one for the job.

Reaching a Home Lab from a Locked-Down Work Laptop with Pure OpenSSH

style-newspaper len:7023 crease:78% color:3 rot:2
Nov 25, 2026 (updated Dec 2, 2026)

The default answers for reaching a home server behind ISP NAT are Tailscale or Cloudflare Tunnel (cloudflared). Both are great—until you hit a common set of constraints:

  • Home LAN (behind NAT): An always-on Raspberry Pi (pi) and a Mac mini (mini).
  • Tiny public VPS (vps): Too small for extra VPN daemons, and also a personal dev box that pushes to personal GitHub repos.
  • Locked-down work laptop (corp-laptop): Cannot install VPN clients, outbound SSH is allowed, corporate keys live dynamically in $SSH_AUTH_SOCK, and corporate keys must never be offered or forwarded to the VPS or the internet.

Plain OpenSSH solves all of it with a few megabytes of RAM, end-to-end encryption, zero third-party control planes, and strict separation between corporate and personal keys. Both server setup scripts—setup-tunnel.sh and persist-tunnel.sh —are hosted right alongside this note; for a zero-key browser-only alternative that needs no VPS and no outbound SSH, see the companion Cloudflare Tunnel browser SSH setup.

Why Pure OpenSSH?

Criterion Pure OpenSSH (Reverse Tunnel + ProxyJump) Tailscale Cloudflare Tunnel (Browser SSH)
Corp laptop Outbound SSH + encrypted personal key Blocked (VPN client) Browser only (HTTPS/443); zero keys
Extra software None (sshd + systemd) Daemon on every node cloudflared + domain + Zero Trust
Trust boundary End-to-end (corp-laptop → target) End-to-end WireGuard CF Edge decrypts browser I/O & signs CA
VPS RAM footprint ~few MB ~30–60+ MB N/A (runs on pi)
Capabilities Full ssh, scp, rsync, -L/-D Built-in (full L3) Interactive xterm.js shell only

Tailscale is still great for mobile devices (e.g., viewing a Pi webcam from a phone), and Cloudflare Tunnel is a strong fallback when you want zero personal keys on corp-laptop. Keeping OpenSSH for daily laptop access gives you native terminal ergonomics and full port forwarding without ever putting the VPS on your tailnet.

Architecture

corp-laptop --(SSH #1)--> vps <--(reverse tunnel :2222)-- pi --(LAN :22)--> mini
     |                                                    ^                  ^
     +----------------(SSH #2, end-to-end)----------------+                  |
     +----------------(SSH #3, end-to-end)-----------------------------------+
  1. Persistent reverse tunnel (pi → vps): pi dials out to vps and binds its SSH port strictly to loopback (127.0.0.1:2222) under a locked-down /bin/false user—nothing new is exposed publicly.
  2. Chained ProxyJump (corp-laptop → vps → pi → mini): Every hop authenticates end-to-end from corp-laptop. No personal private keys live on vps or pi, and ForwardAgent stays off for both.
  3. Isolated personal ssh-agent (~/.ssh/agent.sock): OpenSSH cannot filter dynamically loaded corporate keys per host inside a shared agent. A dedicated, unexported personal socket leaves $SSH_AUTH_SOCK untouched while safely enabling ForwardAgent ~/.ssh/agent.sock to vps for personal GitHub pushes.

1. Reverse Tunnel (pi → vps)

Both scripts assume Debian 12+ or Ubuntu 22.04+. First, generate a dedicated passphrase-free ed25519 key on pi solely for unattended tunnel reconnects:

ssh-keygen -t ed25519 -N "" -C "pi-reverse-tunnel" -f ~/.ssh/id_ed25519_vps_tunnel

On vps, fetch and run setup-tunnel.sh with the Pi’s public key (either as a file argument or piped on stdin):

curl -fLO https://joyus.org/2026/lightweight-ssh-homelab/setup-tunnel.sh
chmod +x setup-tunnel.sh
cat id_ed25519_vps_tunnel.pub | sudo ./setup-tunnel.sh

It creates a /bin/false tunnel user, installs a scoped Match User tunnel drop-in at /etc/ssh/sshd_config.d/99-reverse-tunnel-tunnel.conf, validates with sshd -t (rolling back on error), reloads sshd, and verifies the effective config via sshd -T -C user=tunnel. A few details matter:

  • AllowTcpForwarding remote, GatewayPorts no, and PermitListen localhost:* 127.0.0.1:* [::1]:* restrict forwards strictly to loopback. localhost:* is required because OpenSSH sends localhost on the wire for -R 2222:127.0.0.1:22; allowing only 127.0.0.1:* rejects it.
  • ClientAliveInterval 30 / ClientAliveCountMax 3 scoped inside Match User tunnel clears stale tunnels within ~90s after ISP drops without affecting normal sessions.
  • Keep AllowTcpForwarding yes (the default) for your normal users on vps and pi so ProxyJump (ssh -W) works.

On pi, skip autossh and let systemd + OpenSSH handle reconnects via persist-tunnel.sh , which auto-detects pi’s local sshd port and installs reverse-ssh-tunnel.service:

curl -fLO https://joyus.org/2026/lightweight-ssh-homelab/persist-tunnel.sh
chmod +x persist-tunnel.sh
sudo ./persist-tunnel.sh <VPS_IP> 2222

Verify on vps that port 2222 is listening on loopback only:

ss -tln | grep ':2222\b'
# Expected: LISTEN ... 127.0.0.1:2222 0.0.0.0:*

The critical unit options in reverse-ssh-tunnel.service:

  • -F /dev/null + IdentitiesOnly=yes + IdentityFile=... isolate the daemon from your personal ~/.ssh/config.
  • ExitOnForwardFailure=yes forces an immediate exit (and 10s systemd retry) if vps briefly still holds port 2222 from a dead connection.
  • StartLimitIntervalSec=0 prevents systemd from giving up during multi-hour ISP outages, and BatchMode=yes + StrictHostKeyChecking=accept-new avoids interactive hangs while pinning the VPS host key on first connect.

2. Isolated ssh-agent and ~/.ssh/config

On corp-laptop, never overwrite global $SSH_AUTH_SOCK. Instead, start a dedicated personal agent at ~/.ssh/agent.sock in your shell rc without exporting it (see __setup_ssh_agent in zsh/zshrc and bash/bashrc ). There is no passphrase prompt on terminal startup—OpenSSH unlocks the key lazily on first use via AddKeysToAgent, and modern ed25519 private keys embed their public key unencrypted so no sibling .pub file is needed.

Then adapt config.sample into ~/.ssh/config (chmod 600 ~/.ssh/config): Host vps sets ForwardAgent ~/.ssh/agent.sock; Host pi targets 127.0.0.1:2222 via ProxyJump vps with HostKeyAlias pi; Host mini sets ProxyJump pi; a shared Host vps pi mini github.com block pins IdentityAgent ~/.ssh/agent.sock, IdentityFile ~/.ssh/%u.key, IdentitiesOnly yes, and AddKeysToAgent 10h; and corporate hosts sit above Host *.

Three Subtle OpenSSH Gotchas

  1. Never pass -A (ssh -A vps): CLI flags override ~/.ssh/config. -A sets ForwardAgent yes, dropping ~/.ssh/agent.sock and silently forwarding your corporate $SSH_AUTH_SOCK.
  2. Use HostKeyAlias pi for tunneled targets: Avoids [127.0.0.1]:2222 collisions in ~/.ssh/known_hosts with other port forwards.
  3. Never put corporate IdentityFile lines in Host *: Unlike IdentityAgent or ForwardAgent (first-match-wins), IdentityFile accumulates across every matching block.

3. Day-to-Day Usage

Once wired up, every host and tunnel is one command from corp-laptop:

ssh vps                                 # Dev session (personal GitHub via isolated agent)
ssh pi                                  # corp-laptop -> vps -> pi
ssh mini                                # corp-laptop -> vps -> pi -> mini
ssh -N -L 5900:localhost:5900 mini      # Mac mini Screen Sharing -> vnc://localhost:5900
ssh -D 1080 pi                          # Ad-hoc SOCKS5 proxy into home LAN

Sometimes the boring tool sitting in /usr/bin/ssh for 25 years is still the cleanest one for the job.