Linux for Developers Course
Linux for Developers
/
Advanced

SSH Tunneling (Port Forwarding)

Definition

A method of transporting arbitrary networking data over an encrypted SSH connection. It can be used to bypass firewalls or securely access local services running on remote machines.

Explain Like I'm New

Creating a secret, encrypted underground tunnel from your laptop directly into a locked server, allowing you to access a private database as if it were running on your own computer.

Real World Example

A production database on a server only listens to `localhost:5432` for security. You cannot connect DBeaver from your laptop. You create an SSH tunnel (`ssh -L 5432:localhost:5432 admin@server`). Now, your laptop's local port 5432 is secretly wired to the server's database, and you connect securely.

Common Use Cases

  • •Securely accessing private databases
  • •Bypassing corporate firewalls

Interview Questions

basic

  • Is the data sent through an SSH Tunnel encrypted?

intermediate

  • What is the difference between Local Port Forwarding (`-L`) and Dynamic Port Forwarding (`-D`)?

Flash Cards

Question

Is it encrypted?

Click to reveal answer
Answer

Yes. Every single byte is heavily encrypted by the SSH protocol, protecting it from network sniffers and man-in-the-middle attacks.

Question

Local vs Dynamic?

Click to reveal answer
Answer

Local (`-L`) forwards one specific port to one specific destination (e.g., tunneling just the database). Dynamic (`-D`) turns your SSH connection into a full SOCKS proxy server, allowing you to route your entire web browser's traffic through the remote server to bypass firewalls.