Setting Up SSH Tunnel

Published
Length
3 min read

Luis Felipe Dias

All posts

Engineers start setting up ssh tunnel routes by mapping a local port to a remote service. An intermediary SSH server forwards that encrypted traffic straight to the private destination. Teams often route traffic through a shared bastion or jump host inside the network. Operators grant users static SSH keys or broad shell roles on that middle host. When roles are too broad, anyone with a valid key can reach internal ports. They can also hold open background sockets long after their task finishes.

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Engineers start setting up ssh tunnel routes by mapping a local port to a remote service. An intermediary SSH server forwards that encrypted traffic straight to the private destination. Teams often route traffic through a shared bastion or jump host inside the network. Operators grant users static SSH keys or broad shell roles on that middle host. When roles are too broad, anyone with a valid key can reach internal ports. They can also hold open background sockets long after their task finishes.

How setting up ssh tunnel routes works in practice

An SSH tunnel wraps raw network traffic inside an encrypted shell transport session. The client binds a local port on the laptop of the engineer. When an app sends data to that local port, the SSH client captures it. The client encrypts the packets and sends them to the remote SSH daemon. That daemon decrypts the stream and opens a TCP socket to the target service.

Teams manage entry to this middle host with public keys or OpenSSH certificates. An OpenSSH certificate holds a public key, identity data, principal names, and signed options. A Certification Authority key signs these fields so hosts trust the user key. Certificates use a much simpler format than the X.509 files used in TLS. Admins can also set a validity window when they sign a user certificate. Once the host checks the key or certificate, it opens the requested TCP pipe.

Remote port forwarding works in the reverse direction across the same encrypted transport. The remote SSH server listens on a port and sends traffic back to the client. Dynamic forwarding turns the local SSH client into a SOCKS server for many ports. Each mode relies on the SSH daemon to route TCP bytes between two network sides.

Why teams rely on native SSH port forwarding

Native port forwarding lets teams reach private subnets without opening public firewall ports. Database servers and internal web apps stay hidden on isolated private network segments. Only the bastion host needs a public IP address and an open port. Engineers use standard tools that already exist on their work laptops every day.

The encrypted transport protects data moving across public networks from packet sniffing. Teams do not need to set up TLS on every legacy internal tool right away. Certificate signing also cuts down on manual key files across dozens of Linux hosts. These benefits make native port forwarding a common first step for growing engineering teams.

SSH Tunneling Security + Step-Up Authentication: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where native SSH tunnels fall short in production

An SSH tunnel works at the transport layer and only checks who can log in. Once the TCP pipe opens, the SSH daemon is blind to the traffic inside. If an engineer tunnels to a database, the SSH host sees raw encrypted bytes. It cannot read SQL queries, check HTTP calls, or stop a destructive drop command. The host log shows that a port forward happened, not what data moved.

Users still need raw database passwords or API tokens on their local machines. The tunnel moves packets across the network, but the local app must still log in. Shared passwords end up in local text files, shell history, and app settings. If a laptop gets stolen, those saved secrets put internal data at risk.

Certificate options and host settings can restrict port forwarding to certain network addresses. Yet managing fine rules across many hosts and database roles takes constant manual work. Security teams lack a single place to approve single queries or mask sensitive output. When an audit happens, logs cannot show if a query returned card numbers or emails.

Add command and file guardrails to SSH access

Host firewalls and certificate principals control who opens an SSH session. Yet an allowed user or agent can still run a bad one-shot command or pull sensitive files over sftp. In practice, hoop.dev sits inline on the host as an open-source SSH server with guardrails that uses OpenSSH certificates. For every one-shot command or sftp task an agent or human runs in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev SSH controls, guardrails check one-shot commands, env variable names, and sftp or scp paths before they run. Port forwards default to deny unless the target is listed. Because interactive shells have no statement boundary and carry no guardrails, teams can turn them off so every command is checked and logged. Check out the MIT-licensed project on GitHub.

Frequently asked questions

What is the difference between local and remote SSH port forwarding?

Local forwarding maps a port on your laptop to a remote network service. Remote forwarding opens a port on the server and sends traffic back to your laptop.

Do OpenSSH certificates inspect the queries inside an SSH tunnel?

No, OpenSSH certificates only verify user or host identity when the session starts. They cannot read or filter the database queries or HTTP calls inside the tunnel.

Why do native SSH tunnels still require local database passwords?

An SSH tunnel only provides a network path to the remote database port. Your local client still needs database credentials to log in once the socket opens.

The query runs. The emails stay hidden.