Use it to reach services behind a firewall securely or through a jump host.
SSH Tunneling
SSH tunnelling forwards TCP ports through an SSH connection: local (-L) exposes a remote service on a local port, remote (-R) exposes a local service on the server, and dynamic (-D) creates a SOCKS proxy. ProxyJump (-J) connects through a bastion.
1. Local forward: ssh -L 8080:internal:80 user@bastion -N.
2. ss -ltn | grep 8080 — listening locally?
3. Server allows it: sshd -T | grep -i allowtcpforwarding.
4. Test: curl -I http://localhost:8080.
5. Bastion: ssh -J user@bastion user@target.
SSH session → forwarding requested → server permits → local or remote port listens → traffic carried through the encrypted channel
For SSH → SSH Tunneling, continue with the first unproven Topic check: Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path. If that boundary is healthy, advance to the adjacent check: Verify bind address/port and forwarding policy on the side that owns the listener. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload
Healthy evidence: the intended bind exists, sshd permits the forward, the correct side resolves/connects to the destination and the original application succeeds through the tunnel.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path.
- Verify bind address/port and forwarding policy on the side that owns the listener.
- Test destination reachability from the side that actually opens the forwarded connection.
- Validate the original tunneled application end-to-end, including DNS/TLS/application identity where relevant.
Verification chain. forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload
Step 3 Commands Verify boundary
ssh -L 8443:internal:443 user@jump
ssh -R 9000:localhost:9000 user@host
ssh -D 1080 user@host
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: forward is bound only to loopback when remote access is expected, server policy rejects forwarding, destination is tested from the wrong host or tunnel establishment is mistaken for application success.
Step 5 Common mistakes Narrow the fault
- Leaving tunnels open with
GatewayPortsexposing services.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
The server must allow forwarding (AllowTcpForwarding). Remote forwards bind to localhost unless GatewayPorts allows otherwise. Prefer ProxyJump over agent forwarding.
ssh -v user@host— client-side connection and authentication stepsjournalctl -u ssh -u sshd -e— server logsshd -T— effective server settingsss -ltnp | grep :22— sshd listening
ReferenceWhat it is1 section · depth on demand
Core model
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
A working SSH transport or listening forward shows only part of the tunnel, but it does not show destination reachability, correct resolution side, application identity or service-level success.
In depth
SSH tunnelling: local, remote and dynamic forwarding
SSH can carry other TCP connections through its encrypted channel. The ssh(1) manual page describes three kinds of forwarding:
- Local (
-L): listens on the client and connects, through the server, to a destination on the server's side. - Remote (
-R): listens on the server and connects back to a destination on the client's side. - Dynamic (
-D): runs a SOCKS4/5 proxy on the client, and each request is forwarded to the destination the application asks for.
-N (no command) and -f (background) are useful when the connection only carries forwards. -W connects stdin and stdout straight to a host and port, which is how ProxyJump works internally.
Which forward for which job
| Need | Command |
|---|---|
| Reach a database behind a bastion from your laptop | ssh -N -L 15432:db1.internal:5432 bastion |
| Let a server reach a service on your machine | ssh -N -R 8080:localhost:3000 srv1 |
| Browse an internal web UI through a jump host | ssh -N -D 1080 bastion, then use SOCKS proxy localhost:1080 |
| Hop through a bastion to another SSH server | ssh -J bastion srv1 |
Server-side controls (sshd_config(5))
| Setting | Effect |
|---|---|
AllowTcpForwarding | yes (default), no, local, remote |
GatewayPorts | no (default): remote forwards bind to loopback only |
PermitOpen | Limit the destinations local forwards may reach |
permitopen / permitlisten in authorized_keys | The same limits per key |
admin$ ssh -f -N -L 15432:db1.internal:5432 bastion
admin$ ss -tlnp | grep 15432
LISTEN 0 128 127.0.0.1:15432 0.0.0.0:* users:(("ssh",pid=4122,fd=5))
admin$ psql -h 127.0.0.1 -p 15432 -U app appdb
admin$ ssh -N -D 127.0.0.1:1080 bastion &
admin$ curl --socks5-hostname 127.0.0.1:1080 https://grafana.internal/api/health
admin$ ssh -O check bastion
Master running (pid=4100)
Tunnel bound to loopback
The local forward listens on 127.0.0.1 only, so other machines on the network can't use the tunnel. Bind it to another address only deliberately, for example -L 0.0.0.0:15432:....
SOCKS and DNS
--socks5-hostname makes the far side resolve the name, which matters for internal names your laptop can't resolve itself. If a forward is refused, the server's AllowTcpForwarding or a key restriction is the usual reason. The client's -v output shows "administratively prohibited".
Documented example, not captured output.
How it works at runtime
SSH Tunneling is part of SSH → SSH Tunneling. SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.
Topic-specific state model. SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol.
Interpretation rule. - SSH session established ≠ requested port forward was accepted.
- Local listening socket exists ≠ remote destination connection succeeds.
- Tunnel TCP connect succeeds ≠ application protocol/TLS/authentication succeeds.
localhost≠ same machine from both sides of an SSH tunnel.
Quick reference
SSH tunnelling:
| Type | Command | Use |
|---|---|---|
| Local forward | ssh -L 5433:db01:5432 bastion | Reach a remote service via localhost:5433 |
| Remote forward | ssh -R 8080:localhost:80 public-host | Expose a local service on the remote side |
| Dynamic (SOCKS) | ssh -D 1080 bastion | Browser/tools via SOCKS proxy |
| Jump host | ssh -J bastion target | Multi-hop SSH |
ssh -fNL 5433:db01.internal:5432 bastion # background, no shell
ssh -o ExitOnForwardFailure=yes -NR 2222:localhost:22 relay
Servers can restrict tunnels with AllowTcpForwarding, PermitOpen, GatewayPorts. Persistent tunnels belong in systemd units or autossh.
Limits and how it fails
Primary failure point. A working SSH transport or listening forward shows only part of the tunnel, but it does not show destination reachability, correct resolution side, application identity or service-level success.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. SSH Tunneling owns OpenSSH local/remote/dynamic forwarding semantics. Linux Networking/Firewall own underlying packet paths and filtering; application protocol/TLS behavior belongs to its relevant domain.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in SSH → SSH Tunneling. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.openssh.com/manual.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
SSH Tunneling operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for SSH Tunneling.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin exact client/server + attempt time → resolve destination/TCP path → inspect effective client config → identify OpenSSH versions → verify KEX + host-key trust → trace offered/accepted authentication → inspect effective sshd policy for user/source → verify session/subsystem/forward → verify remote process/filesystem/service → repeat original workload. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | A working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux SSH evidence can establish this proof path: forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured transport, trust, authentication, policy, session, filesystem or workload scope. A working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: correlate client and server evidence for the same attempt, inspect effective client/server configuration and identity/trust/authentication state, then test the exact requested session, transfer or forward before changing additional layers. | Continue to the next unresolved boundary while preserving the original test condition. |
SSH Tunneling · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | SSH Tunneling |
|---|---|
| Topic path | SSH → SSH Tunneling |
| Runtime state | SSH tunneling forwards TCP endpoints through SSH channels using local, remote or dynamic forwarding; success depends on bind/listen scope, name-resolution side, sshd forwarding policy, destination reachability from the relevant endpoint and the tunneled application protocol. |
| Fast checks | - Classify the forward as local, remote or dynamic and draw listener → SSH server → destination path. - Verify bind address/port and forwarding policy on the side that owns the listener. - Test destination reachability from the side that actually opens the forwarded connection. - Validate the original tunneled application end-to-end, including DNS/TLS/application identity where relevant. |
| Verification chain | forward specification → bind/listener → SSH transport/auth → forwarding policy/channel open → destination resolution/connect → application protocol → original workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | A working SSH transport or listening forward proves only part of the tunnel; it does not prove destination reachability, correct resolution side, application identity or service-level success. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |