Skip to content
BENIBIX Learn

SSH Tunnels and Jump Hosts

Level 5 · Reaching further

How an SSH tunnel carries a private service, such as a database, to your laptop. How a jump host lets you reach servers with no public address.

Course contentsLesson 8 of 9

After this lesson you can

  • Open a tunnel with ssh -L
  • Reach a private server with ssh -J
  • Say why both keep things closed

12 mincovers 2 glossary entries

Worth reading first: scp, SFTP and rsync

How to reach what the internet cannot see

An SSH tunnel carries other traffic inside your SSH login. ssh -L 8080:localhost:5432 emma@203.0.113.10 makes port 8080 on your laptop lead to port 5432 on the server. Say a database listens only inside the server. Your laptop can now reach it. Nothing new is opened to the internet.

The pattern reads left to right. 8080 is the port on your laptop. localhost:5432 is where to go, as seen from the server. Point your database app at localhost:8080, and it talks to the database on the server.

The tunnel lasts as long as the login. Add -N to open it without a shell, and stop it with Ctrl-C. Many database apps can open the tunnel for you if you give them the SSH details.

A jump host solves a different problem. Some servers have no public address at all. They sit on a private network, and only one machine at the edge faces the internet. That edge machine is the jump host.

ssh -J jack@bastion.example.com jack@10.0.0.5 logs in to the jump host, then on to the private server, in one command. Your key does the work at both steps. It is never copied to the jump host.

Both tricks keep the attack surface small. The database never listens on the internet. The private servers never get a public address. Only one SSH door is open, and it is the one you already locked down.

A common mistake is to open the database port to the world because a tunnel felt like extra work. Bots scan for open database ports all day. One ssh -L line gives you the same access, with none of the risk.

console
$ ssh -N -L 8080:localhost:5432 emma@203.0.113.10
$ ssh -J jack@bastion.example.com jack@10.0.0.5
jack@db1:~$
First, a tunnel to a database on the server. Then a login to a private server through a jump host.
A tunnel brings a private service to you. A jump host takes you to a private server.

Worked example

Lucy reads her database

Lucy's database on her VPS listens only inside the server, on port 5432. She wants to browse it with a desktop app on her laptop.

She runs ssh -N -L 8080:localhost:5432 shop and points the app at localhost:8080. She sees all her tables, and port 5432 stays closed to the internet.

The words for this lesson2

Check yourself

What does ssh -L 8080:localhost:5432 shop do?

Finished this lesson?

Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.