Skip to content
BENIBIX Learn

SSH Tunnel

Infrastructure🔑 SSH & Remote AccessRemote Access Tools

Also known as SSH Port Forwarding, Local Port Forwarding, ssh -L

A way to send one more link through SSH. It reaches a private service.

Think of it like

Think of it like a secret hall between two homes. You walk through, and no one outside sees.

Example

Emma's database only works from inside her server. She opens a tunnel to it. Her laptop's app then uses port 8080.

Why it matters

You can keep a database off the web and still reach it yourself.

Definition

An SSH tunnel carries another connection inside your SSH login. You pick a port on your own computer. Anything sent to it travels through SSH and comes out on the server's side. That lets you reach a service the server keeps private, like a database. Nothing new has to be opened to the internet.

Example code

bash
ssh -L 8080:localhost:5432 emma@203.0.113.10
Port 8080 on the laptop now leads to the database on port 5432 inside the server.
Top: the laptop's port 8080 goes through SSH to the private database on the server.

Common mistake

Opening the database port to the world instead, just for a quick look. A tunnel gives the same access with no open door.

Key takeaways

  1. 1
    Inside SSH. One login carries both.
  2. 2
    Local port in. Pick a port on your side.
  3. 3
    Private stays private. Nothing new is opened.

Compare

Learn it properly