How-tos

SSH Tunnels: The Unsung Hero of Secure Remote Access

Learn how SSH tunnels provide simple, encrypted remote access to locked-down services—no VPN or extra software needed, with practical examples for local, remote, and dynamic port forwarding.

August 2026 6 min read 11 views 0 hearts

If you've ever needed to access a database on a server that's locked behind a firewall, or you wanted to browse the web securely from a coffee shop, you've probably run into SSH tunnels without even realizing it. They're not flashy, they're not complicated, but they solve one of the most common security problems in remote work: getting data from point A to point B without anyone snooping.

At PythonSkillset, we've seen developers spend hours setting up VPNs and complex proxy configurations when a simple SSH tunnel would do the job in two minutes. So let's talk about what SSH tunnels actually do, and why you should care.

What exactly is an SSH tunnel?

Think of SSH tunneling as creating a private, encrypted pipe between your local machine and a remote server. You connect to the remote server via SSH, and then any traffic you send through that connection gets encrypted and forwarded to a specific destination. The remote server acts as your proxy, making requests on your behalf.

The beauty is that SSH is already on almost every Linux server. You don't need extra software, no VPN client setup, no complex firewall rules. Just an SSH server running on the remote machine, and you're good to go.

Three types of tunnels, one simple concept

SSH tunnels come in three flavors, and each serves a different purpose.

Local port forwarding: Access what's behind the firewall

This is the most common use case. Say you have a MySQL database on a remote server that only listens on localhost. You can't connect directly from your laptop because the database port isn't exposed to the internet.

On your local machine, you run:

ssh -L 3306:localhost:3306 user@remote-server

Now any connection to localhost:3306 on your laptop gets securely forwarded through the SSH tunnel to the remote server's localhost:3306. Your laptop thinks it's talking to a local database, but it's actually talking to the remote one, encrypted end-to-end.

Remote port forwarding: Let outsiders reach your local services

This one is the reverse. Imagine you're developing a web app on your local machine and want to show it to a colleague without deploying it. If your colleague can SSH into a public server, you can create a tunnel that exposes your local port.

ssh -R 8080:localhost:3000 user@public-server

Now your colleague can access public-server:8080 and see your local development server running on port 3000. This is incredibly useful for testing webhooks, sharing demos, or troubleshooting production issues.

Dynamic port forwarding: Your own personal SOCKS proxy

This is the Swiss Army knife. Instead of forwarding a single port, dynamic forwarding creates a SOCKS5 proxy on your local machine.

ssh -D 1080 user@remote-server

You configure your browser or any app to use localhost:1080 as a SOCKS proxy, and all traffic gets routed through the remote server, encrypted. It's like having a VPN without installing one. This works great for accessing region-restricted content or securing your browsing on an untrusted network.

Real-world examples you'll actually use

Accessing a company database from home

Let's say your company's PostgreSQL database lives on a server that only accepts connections from the internal network. You connect to the office VPN first, then run:

ssh -L 5432:internal-db.example.com:5432 user@jump-box

Now your local psql connects to localhost:5432 and you're securely querying the production database. No need to open database ports to the world.

Bypassing firewall restrictions at a hotel

Stuck behind a hotel wifi that blocks SSH? Use a remote tunnel from a server you control:

ssh -R 2222:localhost:22 user@home-server

Now you can SSH into your home server on port 2222, which forwards back to your laptop's SSH. It's a life saver when traveling.

Testing a webhook locally

Working with Stripe or GitHub webhooks? You can use a remote tunnel to expose your local development server:

ssh -R 9000:localhost:8080 user@vps

Configure the webhook to send to http://vps:9000/webhook, and it hits your local server. Debugging becomes trivial.

Security considerations that actually matter

SSH tunnels are secure by design because they use the same encryption as regular SSH. But there are a few things to keep in mind:

  • Tunnels persist after you disconnect unless you explicitly close them. Use -N flag if you only want to forward ports without opening a shell.
  • Multiple users on the same server can create conflicting tunnels. Always check port availability.
  • GatewayPorts on the remote server determines whether remote tunnels bind to localhost or all interfaces. Set it to clientspecified for control.
  • Use SSH keys instead of passwords. You should be doing this anyway for security and convenience.

When not to use SSH tunnels

SSH tunnels aren't a silver bullet. For heavy traffic load balancing or high-availability setups, they add latency and single points of failure. For large file transfers, tools like rsync with SSH are better optimized. And for team-wide access, a VPN might be more manageable.

But for quick, one-off secure connections, SSH tunnels are hard to beat. No extra software, no configuration files, no ongoing maintenance. Just a single command that works across platforms.

So next time you need to reach a locked-down service, skip the VPN setup and try an SSH tunnel first. It might save you half an hour and teach you something you'll use for the rest of your career.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.