0Pricing
Linux Server Deployment & SSH Mastery · Lesson

SSH Port Forwarding (Local/Remote)

Master local and remote port forwarding to securely access internal services or expose local services to a remote network.

SSH Port Forwarding (Local/Remote) is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Secure Tunnels with SSH

SSH isn't just for logging in! It can create secure "tunnels" to forward network traffic.

This technique, called port forwarding, lets you access services that are normally unreachable or insecure.

Think of it as setting up a private, encrypted bridge between different network ports.

Why Use Port Forwarding?

Port forwarding is super useful for developers and sysadmins:

  • Access internal services: Reach a database or web UI on a private network from your local machine.
  • Expose local services: Share a local development server with others on a remote network.
  • Bypass firewalls: Securely connect to services behind restrictive firewalls.

Local Port Forwarding (L)

Local port forwarding creates a tunnel from your local machine to a remote server, then to another destination.

It's like saying: "Hey, any traffic I send to localhost:8000 on my computer, please send it through SSH to remote-server, and from there, forward it to internal-db:5432."

Local Forwarding Syntax

The command for local port forwarding uses the -L flag:

ssh -L [LOCAL_PORT]:[REMOTE_HOST]:[REMOTE_PORT] [SSH_USER]@[SSH_SERVER]

  • LOCAL_PORT: A port on your machine.
  • REMOTE_HOST: The host the SSH server connects to.
  • REMOTE_PORT: The port on REMOTE_HOST.
  • SSH_SERVER: The server you SSH into.

Local Forwarding Scenario

Imagine a database running on db.internal.network:5432. Your SSH server (my-server.com) can reach it, but your laptop can't.

You want to connect to this database using a local tool like DBeaver or psql.

Local forwarding lets you do just that!

Local Forwarding in Action

Let's open a tunnel from your local port 5432 to the remote database db.internal.network:5432 via my-server.com.

ssh -L 5432:db.internal.network:5432 user@my-server.com

Now, any connection to localhost:5432 on your machine will securely reach db.internal.network:5432.

Remote Port Forwarding (R)

Remote port forwarding is the opposite: it creates a tunnel from a remote server back to your local machine, then to a destination.

It's like saying: "Hey, any traffic sent to my-server.com:8080, please send it through SSH to my laptop, and from there, forward it to localhost:3000."

Remote Forwarding Syntax

The command for remote port forwarding uses the -R flag:

ssh -R [REMOTE_PORT]:[LOCAL_HOST]:[LOCAL_PORT] [SSH_USER]@[SSH_SERVER]

  • REMOTE_PORT: A port on the SSH server.
  • LOCAL_HOST: The host the SSH server connects to (usually localhost).
  • LOCAL_PORT: The port on LOCAL_HOST.
  • SSH_SERVER: The server you SSH into.

Remote Forwarding Scenario

You're developing a web app on your laptop at localhost:3000. You want to show it to a colleague, but they're on a different network.

You can use remote forwarding to make your local app accessible via a port on your public SSH server (e.g., my-server.com:8080).

Remote Forwarding in Action

Let's expose your local web app running on localhost:3000 via port 8080 on my-server.com.

ssh -R 8080:localhost:3000 user@my-server.com

Now, your colleague can access your app by navigating to http://my-server.com:8080 in their browser!

Port Forwarding Quiz

SSH port forwarding is a powerful tool. Which statements accurately describe its usage?

Tunnels Secured!

You've mastered SSH port forwarding!

  • Local forwarding (-L) connects your local port to a remote service.
  • Remote forwarding (-R) connects a remote server's port to your local service.

These techniques create secure, encrypted tunnels, letting you manage network access effectively. Keep practicing to integrate them into your workflow!

Frequently asked questions

Is the “SSH Port Forwarding (Local/Remote)” lesson free?

Yes — the full text of “SSH Port Forwarding (Local/Remote)” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.

What will I learn in “SSH Port Forwarding (Local/Remote)”?

Master local and remote port forwarding to securely access internal services or expose local services to a remote network. You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Server Deployment & SSH Mastery?

No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SSH Port Forwarding (Local/Remote)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?

Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. SSH Port Forwarding (Local/Remote)
  2. SSH Tunnels and SOCKS Proxy
  3. SSH Agent and Multi-hop
  4. Secure File Transfer with SCP, SFTP, and rsync
← Back to Linux Server Deployment & SSH Mastery