← All cheatsheets

Network

SSH port forwarding — local, remote, dynamic

## Local forward (most common)
Access a remote port as if it were local.

`ssh -L 8080:localhost:3000 user@host`

Now `http://localhost:8080` on your machine hits port 3000 on `host`.

## Remote forward
Expose a local port to a remote host.

`ssh -R 8080:localhost:3000 user@host`

On `host`, `http://localhost:8080` hits port 3000 on your machine.

## Dynamic (SOCKS proxy)
`ssh -D 1080 user@host` — all traffic through SOCKS5 on local port 1080

## Keep it alive in background
`ssh -fN -L 8080:localhost:3000 user@host`
- `-f` background
- `-N` don't execute remote command