Pcornel
Linux · SSH

SSH Tunneling

Cheat sheet · https://pcornel.dk/topic.php?topic=2807

Back to the Topic

Answer

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.

Remember

The server must allow forwarding (AllowTcpForwarding). Remote forwards bind to localhost unless GatewayPorts allows otherwise. Prefer ProxyJump over agent forwarding.

First checks

  • ssh -v user@host — client-side connection and authentication steps
  • journalctl -u ssh -u sshd -e — server log
  • sshd -T — effective server settings
  • ss -ltnp | grep :22 — sshd listening

Verify in this order

SSH session → forwarding requested → server permits → local or remote port listens → traffic carried through the encrypted channel

Where it usually breaks

First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2807

Confirmation

Confirm action

Continue?