← Back to dashboard
remote-accesstoolingfreshReader view (for NotebookLM)

Remote Access Integration Guide

What is remote access?

The real model

Identity over network position: keys, least-privilege tunnels, zero-trust mesh, audit.

The design principle is identity over location — prove who you are (Ed25519 keys, MFA, an IdP) and open the minimum path. SSH `-L`/`-R` forward arbitrary TCP through an encrypted channel; `ProxyJump` chains through a bastion so only one box has a public port. OpenSSH 10.x already negotiates post-quantum hybrid key agreement (`mlkem768x25519-sha256`) by default and warns when a peer can't. ngrok / `cloudflared` expose localhost over HTTPS for webhook callbacks. Tailscale and Cloudflare Access replace open ports with an identity-gated, MFA-backed path, and Cloudflare issues short-lived SSH certificates. Remote-dev tools like VS Code Tunnels and Claude Code Remote Control are outbound-only too, so a workstation never needs an open port.

Six remote-access primitives

Pick by the shape of the problem: shell, expose-localhost, private mesh, or desktop.

Text
██████╗ ███████╗███╗   ███╗ ██████╗ ████████╗███████╗     █████╗  ██████╗ ██████╗███████╗███████╗███████╗
██╔══██╗██╔════╝████╗ ████║██╔═══██╗╚══██╔══╝██╔════╝    ██╔══██╗██╔════╝██╔════╝██╔════╝██╔════╝██╔════╝
██████╔╝█████╗  ██╔████╔██║██║   ██║   ██║   █████╗      ███████║██║     ██║     █████╗  ███████╗███████╗
██╔══██╗██╔══╝  ██║╚██╔╝██║██║   ██║   ██║   ██╔══╝      ██╔══██║██║     ██║     ██╔══╝  ╚════██║╚════██║
██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝   ██║   ███████╗    ██║  ██║╚██████╗╚██████╗███████╗███████║███████║
╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝    ╚═╝   ╚══════╝    ╚═╝  ╚═╝ ╚═════╝ ╚═════╝╚══════╝╚══════╝╚══════╝

Remote Access Integration Guide

Focus: securely reaching a machine or service that isn't directly exposed — a box behind a firewall, a localhost dev server Daraja needs to call, a Raspberry Pi on the office LAN, an Ubuntu distro inside WSL. Deep on SSH (keys, ~/.ssh/config, bastions, agent, forwarding, hardening), then tunnels, mesh VPN, and remote dev. Covers Windows hosts (OpenSSH Server, RDP) and remote-dev surfaces (VS Code Remote, Claude Code Remote Control) too. Grounded in the OpenSSH man pages and release notes, ngrok, Cloudflare, Tailscale, Microsoft and Anthropic docs; reviewed 2026-10-20 against OpenSSH 10.6p1, cloudflared 2026.10.2 and Tailscale v1.104.1.

Table of contents

  1. Overview & decision tree
  2. SSH keys
  3. The SSH agent (and why forwarding is dangerous)
  4. ~/.ssh/config — host blocks
  5. Bastions & ProxyJump
  6. Port forwarding: -L, -R, -D
  7. Hardening sshd
  8. SSH and WSL Ubuntu
  9. Public tunnels (ngrok, Cloudflare Tunnel, Tailscale Funnel)
  10. VPN & zero-trust (Tailscale, WireGuard, Cloudflare Access)
  11. Windows hosts: OpenSSH Server, RDP, VNC
  12. Remote development
  13. Security checklist
  14. Troubleshooting
  15. codeAmani notes

Official documentation

SourceURLWhat it covers
OpenSSH ssh manualhttps://www.man7.org/linux/man-pages/man1/ssh.1.html-L/-R/-D forwarding, -J jump host, -A, -N, -W, escape sequences
OpenSSH ssh_config (current)https://man.openbsd.org/ssh_config.5~/.ssh/config, ProxyJump, IdentityFile, ControlMaster, WarnWeakCrypto
OpenSSH sshd_config (current)https://man.openbsd.org/sshd_config.5Server hardening, PerSourcePenalties, WarnWeakCrypto, AgentSocketPath, default KexAlgorithms
OpenSSH ssh-keygen (current)https://man.openbsd.org/ssh-keygen.1Key types (Ed25519 default, -sk FIDO, mldsa44-ed25519), certificates, -R
OpenSSH release noteshttps://www.openssh.org/releasenotes.htmlWhat changed per release — PQ key exchange, DSA removal, 10.6 security fixes
ngrok free plan limitshttps://ngrok.com/docs/pricing-limits/free-plan-limitsStatic dev domain, endpoint/bandwidth/request caps, browser interstitial
ngrok agent CLIhttps://ngrok.com/docs/gateway/agent/clingrok http, --url, config add-authtoken
Cloudflare Tunnel (locally-managed)https://developers.cloudflare.com/tunnel/features/locally-managed-tunnels/create-local-tunnel/cloudflared tunnel login/create/route/run, config.yml
Cloudflare Tunnel (remotely-managed, recommended)https://developers.cloudflare.com/tunnel/get-started/Dashboard/API-managed tunnels run with a token
Cloudflare Access for Infrastructure (SSH)https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/use-cases/ssh/ssh-infrastructure-access/Short-lived SSH certificates, per-user policy, SSH command logs
Tailscale CLIhttps://tailscale.com/docs/reference/tailscale-cliup/set/status/ssh/serve/funnel
Tailscale SSHhttps://tailscale.com/docs/features/tailscale-sshtailscale set --ssh, grants + ssh policy, check mode, limitations
Tailscale Funnelhttps://tailscale.com/docs/features/tailscale-funnelPublic HTTPS on ports 443/8443/10000
Windows OpenSSHhttps://learn.microsoft.com/windows-server/administration/openssh/openssh_install_firstuseInstall/enable sshd on Windows 10/11 and Server 2019–2025
Windows OpenSSH keyshttps://learn.microsoft.com/windows-server/administration/openssh/openssh_keymanagementadministrators_authorized_keys, ACLs, ssh-agent service
Remote Desktop on Windowshttps://learn.microsoft.com/windows-server/remote/remote-desktop-services/remotepc/remote-desktop-allow-accessWhich editions can host RDP, enabling it safely
WSL networkinghttps://learn.microsoft.com/windows/wsl/networkingNAT vs mirrored mode, netsh portproxy, Hyper-V firewall
VS Code Remote-SSH / Tunnelshttps://code.visualstudio.com/docs/remote/ssh · https://code.visualstudio.com/docs/remote/tunnelsHost requirements, code tunnel
Claude Code Remote Controlhttps://code.claude.com/docs/en/remote-controlclaude remote-control, outbound-only, Trusted Devices

1. Overview & decision tree

"Remote access" is one verb — reach a thing that's elsewhere — answered by a handful of tools that trade off predictably:

  • SSH — the workhorse for administering a box you can route to. Key-based auth, an encrypted shell, and the underused superpower: port forwarding, which carries an arbitrary TCP stream through the SSH connection so a database on a private subnet looks like it's on your localhost.
  • Public tunnels (ngrok, Cloudflare Tunnel, Tailscale Funnel) — the inverse problem: you have a service on localhost and the public internet needs to reach it over HTTPS. This is exactly the M-Pesa/Daraja callback workflow — Daraja will only POST to a public HTTPS URL, and your laptop isn't one.
  • VPN & zero-trust (WireGuard, Tailscale, Cloudflare Access) — instead of exposing services one port at a time, put the machines on a private encrypted network and gate entry on identity. The firewall stays shut; access is a function of who you are, not where you are.
  • Windows hosts (OpenSSH Server, RDP/VNC) — Windows ships its own sshd, and RDP gives you a graphical desktop. Both stay off the public internet: reach them over the tailnet or behind Cloudflare Access.
  • Remote development (VS Code Remote-SSH and Tunnels, Codespaces, Claude Code Remote Control and cloud sessions) — run your editor or agent UI on one device and execute on another, so the code lives where the CPU, GPU, or private data is.

Security is the constant: keys not passwords, least privilege, MFA, and an audit trail.

What changed in OpenSSH recently

Folklore about SSH ages badly. The current baseline is OpenSSH 10.6p1, released 2026-10-06. OpenSSH said in the 10.6 notes that it will now ship security fixes in more frequent releases rather than batch them, so expect point releases more often and patch promptly.

SinceChangeWhat it means for you
8.8ssh-rsa (RSA/SHA-1 signatures) disabled by defaultAncient servers may reject your RSA key — regenerate as Ed25519 rather than re-enabling SHA-1
9.5ssh-keygen generates Ed25519 by defaultssh-keygen with no flags is already the right answer; -t ed25519 is documentation, not necessity
9.8PerSourcePenalties — sshd's built-in penalty boxThe server already throttles brute-forcers before you install fail2ban
10.0Hybrid post-quantum key agreement mlkem768x25519-sha256 is the client default; DSA removed entirelyHarvest-now-decrypt-later is covered when both ends run ≥10.0. ssh-dss keys are dead — a device that needs DSA needs replacing
10.1ssh warns when a connection negotiates a non-PQ key agreement (WarnWeakCrypto, default on); agent sockets move from /tmp to ~/.ssh/agentA new warning on connect means the server is old — upgrade it, don't silence the warning
10.4Experimental composite PQ signature mldsa44-ed25519 (ssh-keygen -t mldsa44-ed25519)Opt-in only in 10.4
10.5ssh-agent lock / session-bind fix; restrict now covers tunnel forwardingPatch release — upgrade if you rely on agent locking or destination-restricted keys
10.6ssh-mldsa44-ed25519 signatures enabled (keys from the 10.4 experiment must be regenerated); sshd gains WarnWeakCrypto (logs clients using non-PQ KEX); LZ77 compression dictionary disabled after a cross-channel plaintext-recovery attack; command-line usernames containing $ or \ rejected; PubkeyOptions max-pk-ok:N; scp -R deprecatedLeave Compression off; read sshd logs for non-PQ clients; never pipe untrusted input into an ssh command line

Current sshd_config(5) default KexAlgorithms starts mlkem768x25519-sha256, sntrup761x25519-sha512, … — check what a live connection actually negotiated with ssh -v host 2>&1 | grep 'kex: algorithm'.


2. SSH keys

Generate

The private key never leaves your machine; only the .pub half is ever copied anywhere.

Bash
# Ed25519 — small, fast, and the ssh-keygen default since OpenSSH 9.5.
# -C is a free-text comment (shows up in authorized_keys — make it identify the key).
# -f names the file so you can keep per-purpose keys instead of one id_ed25519 for everything.
ssh-keygen -t ed25519 -C "barnabas@codeamani-laptop" -f ~/.ssh/id_ed25519

# Same, with a passphrase-hardened private key: -a sets KDF rounds (higher = slower to
# brute-force if the file is stolen). 100 is a common, comfortable value.
ssh-keygen -t ed25519 -a 100 -C "barnabas@codeamani-laptop" -f ~/.ssh/id_ed25519

# Only if a legacy appliance genuinely can't do Ed25519:
ssh-keygen -t rsa -b 4096 -C "legacy-appliance-only"

Always set a passphrase. An unprotected private key is a bearer token sitting in a file — anyone who copies it is you. The passphrase is what makes a stolen laptop a nuisance instead of a breach, and the agent (§3) means you type it once per boot.

Use one key per device, not one key per human. Losing a laptop should mean deleting one line from authorized_keys, not rotating every server you own.

Hardware-backed keys (MFA for SSH)

A FIDO2 security key turns the SSH key into something you have plus, with a PIN, something you know. The private key can't be copied off the token, so a stolen laptop alone gets an attacker nothing.

Bash
# ed25519-sk = Ed25519 held on a FIDO authenticator. Every signature needs a touch.
# -O verify-required also demands the token's PIN or biometric on each use.
# -O resident stores the key handle ON the token so you can load it on another machine
# with `ssh-keygen -K` (needs a PIN set on the authenticator first).
ssh-keygen -t ed25519-sk -O verify-required -O resident -C "barnabas@yubikey"

The server needs nothing special beyond OpenSSH 8.2+; the .pub goes in authorized_keys like any other key. Keep a second, registered token as a backup.

Post-quantum signatures are not the default yet. OpenSSH 10.6 enables the hybrid ssh-mldsa44-ed25519 signature algorithm and ssh-keygen lists mldsa44-ed25519 as a key type, but Ed25519 remains the ssh-keygen default. Key agreement (session encryption) is already post-quantum by default since 10.0, which is the part harvest-now-decrypt-later attacks target. Don't roll out ML-DSA user keys until every server and client in the path runs ≥10.6.

Install the public half

Bash
# Easiest — needs an existing way in (password auth, or another key already installed)
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com

# Manual equivalent when ssh-copy-id isn't available (permissions matter — see below)
cat ~/.ssh/id_ed25519.pub | ssh user@server.example.com \
  'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

# Verify before you disable password auth — keep the working session open!
ssh -i ~/.ssh/id_ed25519 user@server.example.com

Permissions are enforced, not advisory. ~/.ssh must be 700, private keys 600, and authorized_keys 600. If the mode is looser, ssh refuses the key with UNPROTECTED PRIVATE KEY FILE and sshd silently ignores authorized_keys. This is the #1 cause of "my key just doesn't work" — and the #1 reason not to keep keys on a Windows mount inside WSL (§8).

Host key verification (the direction people forget)

Keys prove you to the server. The host key proves the server to you — it's what stops an on-path attacker from impersonating your bastion.

Bash
# First connect is trust-on-first-use: you're shown a fingerprint and asked to accept.
# Compare it out-of-band against the server's own fingerprint before typing yes:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub    # run on the server

# Pre-seed known_hosts for CI / scripted access instead of disabling checking
ssh-keyscan -t ed25519 server.example.com >> ~/.ssh/known_hosts

# Host key changed (rebuild, re-image, new VM at the same address)? Remove the stale entry:
ssh-keygen -R server.example.com

StrictHostKeyChecking accept-new auto-accepts a first fingerprint but still refuses a changed one — a reasonable middle ground for ephemeral infra. Never StrictHostKeyChecking no: that accepts changed keys too, which is precisely the attack it exists to catch.


3. The SSH agent (and why forwarding is dangerous)

The agent holds your decrypted private key in memory so you type the passphrase once instead of on every connection.

Bash
eval "$(ssh-agent -s)"          # start one (most desktops already run it)
ssh-add ~/.ssh/id_ed25519       # unlock the key into the agent
ssh-add -l                      # list loaded keys
ssh-add -t 8h ~/.ssh/id_ed25519 # auto-expire after 8 hours
ssh-add -c ~/.ssh/id_ed25519    # require confirmation on EVERY use of this key
ssh-add -D                      # drop all keys (do this when you step away)

Set AddKeysToAgent yes in ~/.ssh/config and the key loads on first use automatically. On macOS add UseKeychain yes to persist the passphrase in the Keychain. On Windows, the agent is a service that is disabled by default: Get-Service ssh-agent | Set-Service -StartupType Automatic; Start-Service ssh-agent. Note that Microsoft documents that the Windows agent persists added keys in the registry across sessions, so ssh-add -D when a key should no longer be loaded, and keep the passphrase on the key file.

Since OpenSSH 10.1 the agent's listening socket lives under ~/.ssh/agent/ instead of /tmp, so processes sandboxed away from your home directory can't reach it. OpenSSH 10.6 adds ssh-agent -A and the server-side AgentSocketPath (default user:.ssh/agent) to control where those sockets go.

Agent forwarding: what it actually risks

ForwardAgent yes / ssh -A exposes your local agent's socket on the remote host so you can hop onward using your local keys. The ssh(1) man page is blunt about the consequence:

Users with the ability to bypass file permissions on the remote host (for the agent's Unix-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.

Read that carefully: root on the hop cannot steal your key, but for as long as your session is open they can sign with it — i.e. log in as you to every machine that key opens. On a shared or compromised bastion that's a full lateral-movement primitive.

Use ProxyJump instead (§5). It solves the same problem — reach host B via host A — without ever exposing your agent to A, because the SSH session is encrypted end-to-end from your laptop to B and A only relays bytes. Default ForwardAgent no globally, and if some workflow genuinely needs forwarding, scope it to a single trusted host and pair it with ssh-add -c so each use requires an explicit confirmation:

SSH-CONFIG
Host *
    ForwardAgent no          # default deny

Host trusted-build-box
    ForwardAgent yes         # opt in for exactly one host, deliberately

4. ~/.ssh/config — host blocks

A config block turns a long command into ssh prod, and it's where bastion routing, identity selection and keepalives live. Every tool that shells out to ssh — git, rsync, scp, VS Code Remote-SSH, Ansible — inherits it for free.

SSH-CONFIG
# ~/.ssh/config   (chmod 600)

# ── The bastion: the ONLY box with a public SSH port ──────────────────
Host bastion
    HostName bastion.example.com
    User jumpuser
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes            # offer ONLY this key (see gotcha below)
    ForwardAgent no

# ── A private box reachable only through the bastion ──────────────────
Host app-internal
    HostName 10.0.1.50            # private IP, no public exposure
    User appuser
    ProxyJump bastion             # SSH hops through bastion automatically
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

# ── Pattern matching: one block for a whole fleet ─────────────────────
Host db-* cache-*
    User ops
    ProxyJump bastion
    IdentityFile ~/.ssh/id_ed25519

# ── A distinct key for GitHub (keeps work/personal identities apart) ──
Host github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github
    IdentitiesOnly yes

# ── Shared defaults. MUST BE LAST — see first-match-wins below. ────────
Host *
    AddKeysToAgent yes
    ForwardAgent no
    ServerAliveInterval 60        # ping every 60s...
    ServerAliveCountMax 3         # ...give up after 3 misses (~3 min dead link)
    ControlMaster auto            # reuse one TCP+auth session for repeat connects
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 10m

Three things worth internalising:

  • First match wins, per keyword. ssh_config takes the first value it obtains for each parameter, so a Host * block placed at the top silently freezes every later override. Specific hosts first, Host * at the bottom — always.
  • IdentitiesOnly yes fixes "Too many authentication failures". Without it, ssh offers every key in your agent in turn; servers with the default MaxAuthTries 6 cut you off before reaching the right one. IdentitiesOnly restricts the offer to the IdentityFile you named.
  • ControlMaster makes repeat connections instant. The first ssh prod authenticates; subsequent ones (including every git push and each VS Code channel) ride the existing socket. ControlPersist 10m keeps it warm after you exit. Note that a multiplexed session shares the master's fate — kill it with ssh -O exit prod.

ssh -G app-internal prints the fully-resolved config for a host — the fastest way to find out which block actually won.

Two settings to leave at their defaults: Compression no, because compressing a connection that mixes trusted and untrusted traffic (a shell plus an open port-forward) leaks information about the session, and OpenSSH 10.6 weakened compression on purpose to blunt a cross-channel plaintext-recovery attack; and WarnWeakCrypto yes, the 10.1+ warning that the far end only offers a classical (non-post-quantum) key agreement.


5. Bastions & ProxyJump

The bastion (jump host) pattern: exactly one hardened box has a public SSH port; everything else lives on private IPs and is reached through it. One place to audit, one place to patch, one place to revoke.

SSH-CONFIG
Host app-internal
    HostName 10.0.1.50
    ProxyJump bastion
Bash
ssh app-internal                                        # config-driven
ssh -J jumpuser@bastion.example.com appuser@10.0.1.50   # one-shot equivalent
ssh -J hop1,hop2 user@final-host                        # chain multiple hops

ProxyJump is not agent forwarding. Under the hood it runs a nested ssh -W host:port on the jump host, which merely relays TCP. Your session to the final host is encrypted end-to-end from your laptop — the bastion sees ciphertext, never your keystrokes and never your agent. That property is the whole reason to prefer it.

ProxyCommand is the older, more general escape hatch (ProxyCommand ssh -W %h:%p bastion, or an AWS SSM / Cloudflare cloudflared access ssh invocation). Reach for ProxyJump unless you need something ProxyJump can't express.

On the bastion itself, keep the blast radius small: no application code, no secrets, AllowTcpForwarding yes (it needs it) but AllowAgentForwarding no, per-user accounts, and full session logging.


6. Port forwarding: -L, -R, -D

SSH's most useful and least-known feature: carry an arbitrary TCP stream through the encrypted connection. -N means "no shell, just hold the tunnel open"; add -f to background it.

Bash
# LOCAL forward (-L): pull a remote/private service onto YOUR localhost.
# Reach a Postgres on a private subnet as if it were local:5432.
ssh -N -L 5432:db.internal:5432 user@bastion.example.com
#        └local┘ └──remote target──┘
# → psql -h localhost -p 5432   now hits db.internal through the tunnel.
# The "db.internal:5432" part is resolved BY THE BASTION, not by you — which is
# why this works for hostnames that don't resolve on your machine at all.

# REMOTE forward (-R): push YOUR localhost out to a port on the remote box.
ssh -N -R 8080:localhost:3000 user@server.example.com
# → server.example.com:8080 reaches your laptop's :3000.
# By default this binds the remote's LOOPBACK only. To expose it on the remote's
# public interface the SERVER must set `GatewayPorts yes` (or `clientspecified`),
# then: ssh -N -R 0.0.0.0:8080:localhost:3000 user@server.example.com

# DYNAMIC forward (-D): a local SOCKS5 proxy that egresses from the remote host.
ssh -N -D 1080 user@bastion.example.com
# → curl --socks5-hostname localhost:1080 https://internal-dashboard.example.com
# Point a browser's SOCKS settings at localhost:1080 and every request exits
# from the bastion — the cleanest way to browse an internal admin panel without
# forwarding each service individually.

The mnemonic: -L brings something to you (Local); -R sends something out to the Remote; -D makes everything Dynamic through a SOCKS proxy.

Escape sequences (typed at the start of a line in an interactive session) save you when a forward is missing or a session hangs:

SequenceEffect
~?List all escape sequences
~COpen a command line — add a forward mid-session: -L 8080:localhost:80
~.Kill a hung session (when Ctrl-C won't work)
~&Background the session

On the server side, AllowTcpForwarding no in sshd_config disables all of this — set it on any host that has no business relaying traffic, and leave it on only for bastions.


7. Hardening sshd

The defaults in sshd_config are permissive on purpose — OpenSSH ships something that works everywhere, and expects you to lock it down. These are the directives that matter, with their documented defaults:

DirectiveDefaultSet toWhy
PasswordAuthenticationyesnoPasswords are brute-forced continuously; keys are not
KbdInteractiveAuthenticationyesnoThe forgotten back door — PAM keyboard-interactive still accepts passwords even after you disable PasswordAuthentication
PermitRootLoginprohibit-passwordnoPer-user accounts + sudo give you an audit trail
PubkeyAuthenticationyesyesKeep explicit so a future edit can't quietly flip it
MaxAuthTries63Fewer guesses per connection
AllowUsers / AllowGroupsall usersexplicit listAllowlist beats denylist
PermitEmptyPasswordsnonoAssert it
X11Forwardingno (often yes on distros)noUnused attack surface on a server
AllowTcpForwardingyesno (except bastions)Stops a compromised account pivoting through the box
AllowAgentForwardingyesnoDon't let a hop harvest visiting agents
PerSourcePenaltiesenabled (9.8+)leave onBuilt-in penalty box for crashes, auth failures, invalid users
WarnWeakCryptoyes (sshd 10.6+)leave onLogs every client that negotiates a non-post-quantum key agreement, so you can find stale clients
PubkeyOptions max-pk-ok:N6 (10.6+)leave"Would you accept this key?" probes no longer burn MaxAuthTries, so MaxAuthTries 3 stops locking out agents holding several keys
PermitTunnelnonoLayer-3 tun forwarding is rarely needed; 10.5/10.6 fixed restrict not applying to it

Distro OpenSSH trails upstream. Ubuntu 24.04's package, for example, reports OpenSSH_9.6p1. An sshd that doesn't recognise a keyword refuses to start, so only write version-gated directives (PerSourcePenalties 9.8+, WarnWeakCrypto/PubkeyOptions 10.6+) where ssh -V / sshd -t confirm support. Where they are supported, they're already on by default. examples/sshd-hardening.conf ships them commented out for this reason.

Bash
# Edit, then ALWAYS validate before restarting
sudo nano /etc/ssh/sshd_config
sudo sshd -t                    # syntax check — silence means OK
sudo sshd -T | grep -Ei 'passwordauth|permitrootlogin|kbdinteractive'   # effective config
sudo systemctl restart ssh

# ⚠ Keep your CURRENT session open and verify a NEW one connects before closing it.
# A typo in sshd_config plus a closed last session is a locked-out server.

Two distro gotchas that waste afternoons:

  • Drop-in includes override your edits. Modern sshd_config starts with Include /etc/ssh/sshd_config.d/*.conf, and cloud images ship files there (e.g. 50-cloud-init.conf) that re-enable PasswordAuthentication yes. Because sshd takes the first value obtained, the drop-in wins over your edit further down the main file. Fix or delete that drop-in, or add your own 00-hardening.conf — drop-ins are read in lexical order, so a 99- file would lose to 50-cloud-init.conf — then confirm with sshd -T. examples/sshd-hardening.conf is the template.
  • Ubuntu 22.10+ uses socket activation. ssh.socket owns the listening port, so Port/ListenAddress in sshd_config are ignored. Change the port with systemctl edit ssh.socket (ListenStream=), or disable the socket unit and enable ssh.service instead.

PerSourcePenalties vs fail2ban

Since OpenSSH 9.8, sshd penalises misbehaving source addresses itself — enabled by default, with per-event penalties (auth failure 5s, invalid user 5s, crash 90s, …) accumulating up to a 10-minute cap. For a single host with keys-only auth, that plus PasswordAuthentication no already removes essentially all brute-force value.

fail2ban still earns its place when you want firewall-level bans (dropping packets rather than answering them), longer ban windows, bans shared across services (SSH + nginx + postfix), or a ban list you can inspect and report on.

INI
# /etc/fail2ban/jail.local
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 3

[sshd]
enabled = true
# Ubuntu 24.04 / Debian 12 log SSH to journald and may have NO /var/log/auth.log.
# With the default `backend = auto`, fail2ban then reads nothing and silently
# never bans anyone. Point it at the journal explicitly:
backend = systemd
Bash
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd     # verify it is actually seeing failures

Beyond authorized_keys: SSH certificates

authorized_keys sprawl is the real operational problem at fleet scale — one departing engineer means editing every server. SSH certificates invert it: a CA signs short-lived user certificates, servers trust the CA, and expiry does the revocation for you.

Bash
# On the CA host (protect this key like a root credential)
ssh-keygen -t ed25519 -f ~/ca_user_key -C "codeamani-user-ca"

# Sign a user's public key for 8 hours, valid as principal "appuser"
ssh-keygen -s ~/ca_user_key -I "barnabas@codeamani" -n appuser -V +8h \
  ~/.ssh/id_ed25519.pub          # → produces id_ed25519-cert.pub

# On every server: trust the CA instead of listing individual keys
#   /etc/ssh/sshd_config
#   TrustedUserCAKeys /etc/ssh/ca_user_key.pub

Keep certificate lifetimes short (hours, not months): an 8-hour cert issued after an IdP + MFA login is worth more than any number of authorized_keys audits. Since OpenSSH 10.1, ssh-agent drops expired certificates on its own shortly after they expire. Use OpenSSH ≥10.6 on the CA host: 10.6 fixed a Daylight Saving Time bug in ssh-keygen date handling that could produce certificates with expiry off by an hour.

If you'd rather not run a CA, Tailscale SSH (§10) and Cloudflare Access for Infrastructure (§10) give you the same "identity, not a file on a laptop" property as a managed service. Both issue access from an IdP login with MFA, and Cloudflare's signs a short-lived SSH certificate per session.


8. SSH and WSL Ubuntu

WSL trips people up because there are two operating systems with two separate SSH worlds on one machine. See wsl/CLAUDE_CODE_INTEGRATION.md (§7 configuration, §10 networking) for the WSL fundamentals; this section covers only the SSH-shaped parts.

SSH out of WSL (the common case)

The distro's ~/.ssh is at /home/you/.ssh inside the Linux filesystem, entirely separate from Windows' C:\Users\you\.ssh. Simplest correct answer: generate a distro-local key and treat the distro as its own device.

Bash
# Inside Ubuntu on WSL
ssh-keygen -t ed25519 -a 100 -C "barnabas@wsl-ubuntu"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com

Do not symlink ~/.ssh to /mnt/c/Users/you/.ssh. Without [automount] options = "metadata" in /etc/wsl.conf, everything under /mnt/c reports mode 0777, and ssh refuses the key outright with UNPROTECTED PRIVATE KEY FILE. Enabling metadata (then wsl --shutdown, then chmod 600) does make it work, but you've now got one key whose permissions depend on a mount option — a fragile setup. Copying the key in and chmod 600-ing it, or issuing a separate key, is the durable choice.

If you want a single key custody point across both OSes, bridge the Windows agent into WSL with npiperelay + socat (or a wrapper like wsl2-ssh-agent) and set SSH_AUTH_SOCK in your shell rc. That keeps the private key in the Windows agent — or in 1Password/ssh-agent.exe — with WSL holding no key material at all. Worth the setup cost only if you're already curating Windows-side keys.

SSH into WSL

Two distinct problems: getting sshd running inside the distro, and making the distro reachable at all.

Bash
# 1. Install and start the server inside Ubuntu
sudo apt update && sudo apt install -y openssh-server
sudo ssh-keygen -A                      # generate host keys if the install didn't

# Avoid colliding with the Windows host's own OpenSSH server on :22
sudo sed -i 's/^#\?Port .*/Port 2222/' /etc/ssh/sshd_config
sudo sed -i 's/^#\?PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sshd -t

# 2. Start it. With systemd enabled ([boot] systemd=true in /etc/wsl.conf):
sudo systemctl enable --now ssh
# Without systemd, WSL has no init — start it per session (or from ~/.bashrc):
sudo service ssh start

Reachability depends on the networking mode:

ModeReaching WSL's sshdNotes
NAT (default)From Windows itself, localhost:2222 generally works via localhost forwarding. From another machine on the LAN it does not — the distro is a VM behind NATBridge it with netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2222 connectaddress=$(wsl hostname -I) — but the WSL IP changes on restart, so this needs re-running
Mirrored (networkingMode=mirrored in %UserProfile%\.wslconfig; Win 11 22H2 + WSL 2.0.9+)WSL mirrors the host's interfaces, so a LAN peer can reach the distro directlyRequires opening the Hyper-V firewall for inbound: Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow, or a targeted New-NetFirewallHyperVRule per port

Remember wsl --shutdown after editing .wslconfig — the setting only applies to a fresh VM.

The codeAmani answer is usually neither. Run Tailscale inside the distro (or on the Windows host with mirrored networking) and reach it by MagicDNS name over the tailnet — no port forwarding, no IP that changes on reboot, no router config, and identity-gated access. Reserve the portproxy dance for one-off LAN testing.


9. Public tunnels (ngrok, Cloudflare Tunnel, Tailscale Funnel)

Stripe, Clerk, Daraja and every other webhook provider POST to a public HTTPS URL. Your dev server on http://localhost:3000 is invisible to them. A tunnel gives localhost a public HTTPS front door. All three options below make an outbound connection from your machine, so no inbound firewall rule or router port-forward is ever needed.

For Stripe specifically, stripe listen --forward-to localhost:3000/api/webhooks/stripe delivers test-mode events to localhost without any public tunnel (see the stripe/ guide). Reach for a tunnel when the provider can only call a URL, as Daraja and Clerk do.

ngrok — fastest path

Bash
# One-time: register your account's authtoken (it lands in ngrok.yml — never commit that file)
ngrok config add-authtoken <YOUR_NGROK_AUTHTOKEN>

# Ephemeral URL — fine for a five-minute test
ngrok http 3000

# Better: bind your account's free STATIC dev domain so the URL survives restarts
ngrok http 3000 --url https://<YOUR-DEV-DOMAIN>.ngrok-free.app

Every ngrok account, free included, gets one automatically assigned static dev domain. Bind it with --url and the callback URL you registered stays valid across restarts. --subdomain and --hostname are deprecated in favour of --url.

Free plan limits, as the sibling networking/ guide verified on 2026-10-20 against ngrok's free-plan page (agent 3.39.11):

LimitFree plan
Dev domains1 (static, auto-assigned)
Online endpoints3
Data transfer out1 GB / month
HTTP requests20,000 / month (4,000 / minute)
TCP connections5,000 / month
Browser trafficInterstitial warning page on HTML responses; webhook POSTs are unaffected; send ngrok-skip-browser-warning to bypass

The inspector at http://127.0.0.1:4040 replays every request and response. It's the single most useful thing about ngrok when a callback payload isn't what you expected.

Cloudflare Tunnel (cloudflared) — durable, on your own domain

cloudflared makes an outbound-only connection to Cloudflare's edge. Your firewall stays fully closed to inbound traffic, and you get a stable hostname on your own domain, which matters when a provider allowlists callback domains. Current release: cloudflared 2026.10.2.

Cloudflare now recommends remotely-managed tunnels for most uses: you create the tunnel and its routes in the dashboard (Networking → Tunnels) or by API, and the host just runs cloudflared with a tunnel token. Locally-managed tunnels, configured with config.yml, are documented as the option for local development, testing and legacy setups. That's exactly the dev-callback case, so the CLI flow below is fine for a laptop:

Bash
cloudflared tunnel login                                   # browser auth; writes cert.pem
cloudflared tunnel create daraja-dev                       # named tunnel + UUID + credentials JSON
cloudflared tunnel route dns daraja-dev cb.codeamani.com   # CNAME → <UUID>.cfargotunnel.com

# ~/.cloudflared/config.yml
#   tunnel: <UUID>
#   credentials-file: /home/you/.cloudflared/<UUID>.json
#   ingress:
#     - hostname: cb.codeamani.com
#       service: http://localhost:3000
#     - service: http_status:404

cloudflared tunnel run daraja-dev                          # bring it up
cloudflared tunnel info daraja-dev                         # check its connections

# Throwaway alternative — no account, no config, random *.trycloudflare.com URL.
# Quick Tunnels cap at 200 in-flight requests and don't support SSE.
cloudflared tunnel --url http://localhost:3000

Two credentials, two blast radii: cert.pem (from tunnel login) can create, route and delete any tunnel in the account and is valid for at least 10 years; the per-tunnel <UUID>.json can only run that one tunnel. Once your tunnels exist, Cloudflare's docs suggest deleting cert.pem and managing DNS from the dashboard. Both files are secrets.

Tailscale Funnel

tailscale funnel 3000 publishes a local port at https://<device>.<tailnet>.ts.net. It needs MagicDNS, HTTPS certificates and the funnel node attribute enabled in the policy file, only listens on ports 443, 8443 and 10000, and has bandwidth limits you can't configure. Use tailscale serve instead when only tailnet members should reach the service. That's the safer default for anything that isn't a webhook.

ngrokCloudflare TunnelTailscale Funnel
Setupsecondsa few minutesseconds (if already on the tailnet)
URLfree static dev domain; custom on paidyour own domain hostname<device>.<tailnet>.ts.net
Needs a domain you ownnoyes (a Cloudflare zone)no
Inbound portsnonenone (outbound-only)none
Put identity in front of itngrok traffic policyCloudflare Access policyuse tailscale serve (tailnet-only) instead of Funnel
Best forthrowaway webhook testing, request inspectionlonger-lived previews, allowlisted callback domainssharing a dev service you're already meshing

10. VPN & zero-trust (Tailscale, WireGuard, Cloudflare Access)

Tunnels and bastions expose one path at a time. A zero-trust mesh flips the model: machines join a private encrypted network and access is granted by identity + policy, not by where a packet originates. No inbound port is open anywhere, and logging in goes through your IdP, with its MFA.

Tailscale (managed WireGuard mesh)

Tailscale builds an encrypted peer-to-peer WireGuard mesh (a "tailnet"). Devices authenticate against your IdP (Google, Microsoft, GitHub, Okta…), so your IdP's MFA is your VPN's MFA. Current client: v1.104.1.

Bash
tailscale up                       # auth via browser/IdP, join the tailnet
tailscale status                   # peers + their 100.x.y.z addresses
tailscale ip -4                    # this device's tailnet IPv4

tailscale set --ssh                # enable identity-gated Tailscale SSH on THIS device
ssh pi@raspberry-pi                # connect by MagicDNS name — no authorized_keys at all
tailscale ssh pi@raspberry-pi      # equivalent via the Tailscale CLI

tailscale serve 3000               # share a local port with your tailnet only
tailscale funnel 3000              # ...or with the whole internet (see §9)

tailscale set --ssh is the documented way to turn the SSH server on (tailscale up --ssh still works). Access needs two things in the tailnet policy file: a grants entry allowing the network connection, and an ssh rule allowing the login. Tailscale's policy language now uses grants; older examples use the legacy acls section.

JSON
{
  "grants": [
    { "src": ["autogroup:member"], "dst": ["autogroup:self"], "ip": ["*"] },
    { "src": ["group:ops"],        "dst": ["tag:prod"],       "ip": ["tcp:22"] }
  ],
  "ssh": [
    {
      "action": "accept",
      "src":    ["autogroup:member"],
      "dst":    ["autogroup:self"],
      "users":  ["autogroup:nonroot"]
    },
    {
      "action": "check",
      "src":    ["group:ops"],
      "dst":    ["tag:prod"],
      "users":  ["autogroup:nonroot"]
    }
  ]
}

"action": "check" forces a fresh IdP login, and so MFA, before the session starts. The default checkPeriod is 12h. The range is 1 minute to 168 hours, or "always". Changing it from 12h is an "Advanced Tailscale SSH" feature on the pricing page, so on the free plan check mode runs at the default period. Use check for production. Neither src nor dst may be a bare *. When both a check and an accept rule match a connection, the check rule wins.

Limits to plan around (from the Tailscale SSH docs):

  • The SSH server runs only on Linux and the macOS open-source tailscaled build. Not Windows, not the App Store macOS app, not Synology or QNAP. Any platform can be a client.
  • Port 22 is assumed and not configurable. Restarting tailscaled (for example, an upgrade) drops live sessions.
  • Any OS user on the client can use it, since no local key file is involved. Avoid it on shared multi-user client machines.
  • "checkPeriod": "always" breaks automation such as Ansible.
  • Session recording exists, sold as a platform extension.

Pricing (tailscale.com/pricing, 2026-10-20): Personal $0 for up to 6 users, unlimited user devices, 3 ACL groups, 50 tagged resources, basic Tailscale SSH on up to 5 hosts. Standard $8/user/month. Premium $18/user/month, which adds advanced Tailscale SSH. Extra tagged resources cost $1/month each. MagicDNS gives stable names (raspberry-pi) instead of 100.x.y.z addresses; use names in scripts.

The default policy lets every device reach every device. Replace it with explicit grants before any production machine joins the tailnet.

WireGuard (the raw protocol)

Tailscale is WireGuard with identity, key distribution and NAT traversal added. Plain WireGuard (wg, wg-quick up wg0) is the DIY option: you manage keys and peer config yourself. Reach for it when you want a single self-hosted VPN concentrator and no third party in the path, and accept that key rotation, device revocation and MFA become your job. WireGuard has no user identity of its own.

Cloudflare Access (zero-trust for HTTP, SSH and RDP)

Pairs with Cloudflare Tunnel: put an internal app behind a Tunnel, then enforce an identity policy (email domain, IdP group, MFA, device posture) at Cloudflare's edge before any request reaches your origin. No open port, and for HTTP apps no client either.

For SSH, Cloudflare's current recommendation is Access for Infrastructure: the server connects through cloudflared, users run the Cloudflare One Client (the device client formerly called WARP), and Access issues a short-lived SSH certificate per login. The server trusts a Cloudflare SSH CA through TrustedUserCAKeys, so there are no authorized_keys to manage. It also gives per-target and per-Unix-user policies plus SSH command logs, and works with native SSH clients. The same infrastructure applications cover RDP targets.

The older short-lived certificates (legacy) flow, which uses a cloudflared access ssh ProxyCommand and a browser login, still works but Cloudflare marks it not recommended for new deployments. You'll recognise it from this config:

SSH-CONFIG
Match host vm.example.com exec "cloudflared access ssh-gen --hostname %h"
    HostName vm.example.com
    ProxyCommand cloudflared access ssh --hostname %h
    IdentityFile ~/.cloudflared/vm.example.com-cf_key
    CertificateFile ~/.cloudflared/vm.example.com-cf_key-cert.pub

11. Windows hosts: OpenSSH Server, RDP, VNC

OpenSSH Server on Windows

Windows ships Microsoft's build of OpenSSH, serviced through Windows Update.

Windows releaseOpenSSH Server state
Windows 10 1809+ / 11, Server 2019 / 2022Not installed — add the optional feature
Windows Server 2025Installed but not enabled — turn on "Remote SSH Access" in Server Manager or start sshd
PowerShell
# Elevated PowerShell (Windows 10/11, Server 2019/2022)
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name 'OpenSSH-Server-In-TCP'   # setup creates this inbound :22 rule

Windows-specific traps:

  • Administrators use a different key file. For an account in the local Administrators group, sshd ignores C:\Users\<you>\.ssh\authorized_keys and reads C:\ProgramData\ssh\administrators_authorized_keys. That file must be ACL'd to Administrators and SYSTEM only, or sshd ignores it: icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
  • Entra ID (Azure AD) accounts can't use key-based auth. Use a local or Active Directory account.
  • Windows sshd supports only password and publickey authentication. Set PasswordAuthentication no in C:\ProgramData\ssh\sshd_config once keys work, then Restart-Service sshd.
  • The setup rule opens :22 to every network profile. Scope it: keep it on the tailnet or LAN only, never router-forwarded.

RDP

  • Windows Home editions can't host Remote Desktop. They can only be RDP clients. Hosting needs Pro, Enterprise, Education or Server. On a Home machine, use OpenSSH, VS Code Tunnels or Claude Code Remote Control instead.
  • Never expose RDP (TCP/UDP 3389) to the internet. Microsoft's own guidance says router port-forwarding RDP "isn't recommended" and prefers a VPN; RDP brute-forcing is a classic ransomware entry vector. Keep Network Level Authentication on, so a session is only created after the user authenticates.
  • Reach it over the tailnet (mstsc /v:win-box using the MagicDNS name, with the Windows firewall scoped to the Tailscale interface), through an SSH local forward (ssh -N -L 13389:localhost:3389 user@win-box, then connect to localhost:13389), or through Cloudflare Access for Infrastructure.

VNC

VNC's native authentication is weak and its traffic is often unencrypted. The tunnel isn't optional hardening, it is the security: ssh -N -L 5900:localhost:5900 user@host, then point the VNC client at localhost:5900, with the VNC server bound to loopback only.


12. Remote development

Run the editor or agent UI on one device and execute on another, so code lives next to the data, GPU, or private network it needs.

SurfaceHow it connectsInbound port on the target?Identity
VS Code Remote-SSHYour ~/.ssh/config (so ProxyJump/ControlMaster just work); installs VS Code Server on the hostSSH (22) — keep it on the tailnetSSH key
VS Code Remote Tunnelscode tunnel on the host, open https://vscode.dev/tunnel/<machine>/<folder>None — outbound to Microsoft's tunnel serviceGitHub or Microsoft account on both ends
Dev Containers / CodespacesContainerised environment, local or GitHub-hostedn/aGitHub
Claude Code Remote Controlclaude remote-control on your machine; drive it from claude.ai/code or the Claude appNone — outbound HTTPS to the Anthropic APIclaude.ai subscription login (+ optional Trusted Devices)
Claude Code cloud sessionsRuns on Anthropic's cloud at claude.ai/code; pull into a terminal with claude --teleportn/aclaude.ai account + GitHub

VS Code Remote-SSH host requirements: x86_64 glibc Linux (kernel ≥3.10, glibc ≥2.17; Alpine/musl unsupported), ARMv7l/ARMv8l Linux, Windows 10 / Server 2016/2019 (1803+) with the official OpenSSH Server, or macOS 10.14+ with Remote Login. Plan for at least 1 GB RAM; 2 GB and 2 cores are recommended. On shared Linux hosts, enable Remote.SSH: Remote Server Listen On Socket so other users can't reach your server's port.

VS Code Remote Tunnels: code tunnel (add --accept-server-license-terms for scripts), code tunnel service install to keep it running, code tunnel unregister to remove it. Up to 10 registered tunnels per account. The session inside the tunnel is end-to-end SSH-encrypted. Because anyone who controls that GitHub/Microsoft account controls the machine, put MFA on it.

Claude Code Remote Control keeps Claude Code running on your machine (filesystem, MCP servers, tools) and makes claude.ai/code or the iOS/Android app a window into it:

Bash
claude remote-control                 # server mode: prints a session URL (spacebar = QR code)
claude remote-control --spawn worktree --name "codeAmani dashboard"   # isolated worktree per session
claude --remote-control               # normal interactive session, also reachable remotely (alias --rc)
# inside a running session:  /remote-control   (alias /rc)
  • Needs a Pro, Max, Team or Enterprise subscription signed in with /login. API keys, Bedrock, Google Cloud, Foundry and a non-default ANTHROPIC_BASE_URL aren't supported. On Team/Enterprise an Owner must enable it.
  • Security model from the docs: the local session makes outbound HTTPS requests only and never opens inbound ports. Traffic goes over TLS through the Anthropic API, using several short-lived, single-purpose credentials.
  • Turn on Trusted Devices (beta; off by default; Pro/Max users enable "Require trusted devices" themselves). Each browser, phone or desktop app must then enroll after a full sign-in, and steering a session needs a sign-in less than 18 hours old or a Face ID / Touch ID / Windows Hello / passkey step-up.
  • Whoever can steer the session can approve its tool calls on your machine. Keep a normal permission mode for sessions you drive from a phone, and avoid bypassPermissions there.

Claude Code over plain SSH still works: it's a terminal app, so ssh app-internal, then claude. On Windows, run it inside WSL Ubuntu, or use the Desktop app's WSL sessions, which run the Claude Code process inside a WSL 2 distribution (WSL 1 isn't supported). See wsl/CLAUDE_CODE_INTEGRATION.md.


13. Security checklist

Remote access is the front door to your infrastructure — treat every item as mandatory, not optional.

  • Keys, never passwords. PasswordAuthentication no and KbdInteractiveAuthentication no on every server; Ed25519 keys; every private key passphrase-protected and held by an agent.
  • One key per device, not per human. Losing a laptop should mean deleting one line, not rotating an estate.
  • Verify host keys. StrictHostKeyChecking accept-new at minimum; never no. Check the fingerprint out-of-band on first connect to anything that matters.
  • Least privilege. One bastion with a public port; everything else private via ProxyJump. Per-user accounts, PermitRootLogin no, AllowUsers allowlists.
  • No agent forwarding. ForwardAgent no globally and AllowAgentForwarding no server-side; use ProxyJump. If some workflow truly needs it, scope it to one host and add ssh-add -c.
  • Turn off forwarding where it isn't needed. AllowTcpForwarding no on every host that isn't a bastion.
  • MFA / identity. Gate SSH and internal apps behind an IdP + MFA (Tailscale SSH in check mode, Cloudflare Access for Infrastructure) rather than a bare key on a stolen laptop. Where a raw key is unavoidable, make it a FIDO ed25519-sk key with verify-required.
  • Short-lived over long-lived. SSH certificates (TrustedUserCAKeys, hours not months) or a managed identity layer that issues them for you beat authorized_keys sprawl once you pass a handful of servers.
  • Stay current. OpenSSH ≥10.6 on servers and clients; post-quantum key agreement is then automatic, and WarnWeakCrypto flags any peer that isn't. OpenSSH now ships security fixes in more frequent releases, so patch promptly.
  • No inbound ports on dev machines. Remote Control, VS Code Tunnels, Tailscale and cloudflared are all outbound-only. A developer laptop or Windows workstation should have nothing router-forwarded, and RDP never faces the internet.
  • No raw exposure. RDP/VNC/databases never face the internet — tunnel or mesh them.
  • Outbound-only where possible. Cloudflare Tunnel and Tailscale need zero inbound firewall rules — nothing to scan, nothing to brute-force.
  • Validate before you restart. sudo sshd -t, then confirm a new session connects before closing the one you have.
  • Rotate & revoke. Remove departed users from authorized_keys on every server, from the tailnet, from Cloudflare Access, and from claude.ai Trusted Devices, the same day.
  • Audit. Log SSH sessions and access decisions; Tailscale and Cloudflare give you a who-reached-what trail out of the box.
  • Tunnel credentials are secrets. ngrok authtoken, cloudflared cert.pem and credentials JSON, tunnel tokens, WireGuard private keys, SSH CA keys → .env.local / Hazina, never committed, caught by the pre-push gitleaks gate.

14. Troubleshooting

SymptomLikely cause / fix
Permission denied (publickey)Public key not in the server's authorized_keys, or wrong user. Diagnose with ssh -vvv user@host and read which keys were offered
UNPROTECTED PRIVATE KEY FILEchmod 600 ~/.ssh/id_ed25519, chmod 700 ~/.ssh. On WSL, the key is probably on /mnt/c — move it into the Linux filesystem (§8)
Key ignored server-side, no error~/.ssh or authorized_keys too permissive on the server; sshd silently skips them. Check sudo journalctl -u ssh
Too many authentication failuresThe agent is offering every key before the right one. Add IdentitiesOnly yes + an explicit IdentityFile
REMOTE HOST IDENTIFICATION HAS CHANGEDServer rebuilt/re-imaged (or an on-path attack). Confirm the cause, then ssh-keygen -R host
Config edits have no effectFirst-match-wins: an earlier block (often Host * at the top) already set the keyword. Check with ssh -G host
sshd still accepts passwords after disablingEither KbdInteractiveAuthentication yes is still on, or a drop-in in /etc/ssh/sshd_config.d/ overrides you. Verify with sudo sshd -T | grep -i auth
Port change in sshd_config ignored (Ubuntu 22.10+)ssh.socket owns the port — systemctl edit ssh.socket and set ListenStream=
-R forward not reachable from outside the remoteRemote binds loopback by default; needs GatewayPorts yes server-side and -R 0.0.0.0:PORT:...
Connection drops after idleServerAliveInterval 60 + ServerAliveCountMax 3 in ~/.ssh/config
fail2ban never bans anything (Ubuntu 24.04)No /var/log/auth.log; set backend = systemd in the [sshd] jail
Webhook provider gets a 404 through the tunnelTunnel points at the wrong port, or cloudflared ingress falls through to http_status:404 — hostname must match exactly
ngrok shows a warning page instead of the appFree-plan browser interstitial. Harmless for webhooks; send ngrok-skip-browser-warning to bypass
Can't reach WSL's sshd from another machineDefault NAT mode. Use networkingMode=mirrored + a Hyper-V firewall rule, or netsh interface portproxy (§8)
Tailscale SSH refuses the connectionMissing the ssh rule in the policy file — a network grants entry alone isn't enough. Also check the target is Linux or open-source macOS tailscaled (no Windows SSH server)
New warning on connect about a non-post-quantum key exchange (10.1+)The server only offers classical key agreement: an OpenSSH older than 9.0 (which made the sntrup761 hybrid the default) or another implementation without ML-KEM/sntrup. Upgrade it. As a per-host stopgap only, WarnWeakCrypto accepts a no-pq-kex flag to silence just that warning
ssh rejects a username containing $ or \ (10.6+)Deliberate injection hardening for command-line usernames. Put the name in a User line in ~/.ssh/config if it is genuinely needed
Windows admin account: key ignoredAdmins read C:\ProgramData\ssh\administrators_authorized_keys, which must be ACL'd to Administrators + SYSTEM only (§11)
Can't RDP into a Windows Home PCHome editions can't host RDP. Use OpenSSH Server, VS Code Tunnels or Claude Code Remote Control
claude remote-control errors "requires claude.ai subscription auth"An API key / token is taking precedence. Unset ANTHROPIC_API_KEY (and any apiKeyHelper), then /login
VS Code Remote-SSH fails on an Alpine hostmusl-based distros aren't supported; use a glibc distro or a Dev Container

15. codeAmani notes

  • Webhook tunneling is the everyday use case. For Stripe (the default payment rail) prefer stripe listen --forward-to in test mode; for Clerk and other URL-only providers, use the ngrok static dev domain or cloudflared. Kenya-targeted projects: Daraja only POSTs to public HTTPS. Locally: ngrok http 3000 --url https://<your-dev-domain>.ngrok-free.app — bind the free static dev domain so the callback URL you register survives restarts (the old "re-register a new random URL every time" ritual is obsolete). Test against sandbox shortcode 174379 / test phone 254708374149 before going live. For a hostname a provider can whitelist, use cloudflared mapped to cb.codeamani.com → http://localhost:3000. Either way the callback lands on app/api/mpesa/callback/route.ts — and Daraja callbacks are effectively single-shot, so dedupe on CheckoutRequestID and pair with a status-query reconciliation job (see MPESA_PATTERNS.md and the webhooks guide).
  • One key per device, ~/.ssh/config for everything else. Every codeAmani machine gets its own Ed25519 key with a passphrase; ~/.ssh/config carries IdentitiesOnly yes, ForwardAgent no, ControlMaster auto, and ProxyJump for anything private. examples/ssh-config in this folder is the template to copy.
  • WSL is a separate device. The Ubuntu distro on a Windows workstation gets its own key (barnabas@wsl-ubuntu), not a symlink to C:\Users\…\.ssh — /mnt/c can't hold 600 without the metadata mount option, and ssh refuses the key. Cross-ref wsl/CLAUDE_CODE_INTEGRATION.md for the networking modes; §8 above covers the SSH specifics.
  • Raspberry Pi administration. A Pi on the office LAN should not have SSH exposed to the internet. Put it on the tailnet (tailscale set --ssh on the Pi) and reach it as ssh pi@raspberry-pi from anywhere — identity-gated, no router port-forwarding, no dynamic-DNS hacks. The raspberry-pi guide covers the device side.
  • Zero-trust over open ports. For any internal tool (a staging dashboard, an admin panel), prefer Cloudflare Tunnel + Access or Tailscale over opening a port. The firewall stays shut and access is a function of identity — the same posture as Clerk-everywhere on the app side. New server-SSH setups behind Cloudflare use Access for Infrastructure (short-lived certs, command logs), not the legacy cloudflared access ssh flow.
  • Windows workstations (Windows 11 Home). Home can't host RDP, so remote work on the main dev box goes through Claude Code Remote Control (outbound-only; turn on Trusted Devices), VS Code Tunnels, or OpenSSH Server reachable only over the tailnet. Never router-forward 22 or 3389.
  • Claude Code from a phone. claude --remote-control (or /rc in a running session) is the sanctioned way to keep steering a local session away from the desk. It needs a claude.ai Pro/Max login, not an API key, so it doesn't apply to API-key-driven automation.
  • Bastion pattern for managed DBs. When a Supabase/Neon-style resource sits behind a private network, ssh -N -L 5432:db.internal:5432 user@bastion gives you local psql/migration access through an encrypted tunnel — no need to widen the DB's IP allowlist. Tear the tunnel down when the migration finishes.
  • Secrets hygiene. cloudflared credential JSONs, ngrok authtokens, WireGuard private keys and SSH CA keys are credentials. They live in .env.local / Hazina and are caught by the pre-push gitleaks gate — never pasted in chat, never committed.