Secure SSH Tunnel

Published
Length
3 min read

Luis Felipe Dias

All posts

You build a secure ssh tunnel by using signed OpenSSH certificates and strict port rules. This path sends network traffic from a local machine to a remote server in safety. Many teams start by sharing static public keys on a central jump host. That old habit gives users broad network reach across every internal server. When keys never expire, one stolen laptop puts your whole network at risk. Tighter rules stop lateral movement before it starts. How a secure ssh tunnel works with OpenSSH A tu

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.

You build a secure ssh tunnel by using signed OpenSSH certificates and strict port rules. This path sends network traffic from a local machine to a remote server in safety. Many teams start by sharing static public keys on a central jump host. That old habit gives users broad network reach across every internal server. When keys never expire, one stolen laptop puts your whole network at risk. Tighter rules stop lateral movement before it starts.

How a secure ssh tunnel works with OpenSSH

A tunnel wraps normal network traffic inside an encrypted SSH session. Your local client listens on a chosen port on your computer. When an app talks to that local port, the SSH client grabs the data. It sends those packets down the encrypted pipe to the remote host. The remote SSH server unpacks the data and forwards it to the target destination.

To lock this down, you can replace static keys with OpenSSH certificates. An OpenSSH certificate holds a public key, an identity string, and valid principal names. It also holds a set of options signed by a central authority key. This format is much simpler than the X.509 certificates used in web traffic.

Your authority key signs a user key to make a user certificate. It can also sign a server key to make a host certificate. During signing, you set a key identity and list the allowed user or host names. You also set a strict time window so the certificate expires on time. Without a time window, an OpenSSH certificate stays valid forever by default. You can also embed rules that limit which ports a user can forward.

Why network tunnels still leave a control gap

OpenSSH certificates and bastion hosts solve the login problem very well. They prove who can open a tunnel and when that permission ends. They also stop users from trusting fake remote servers during the handshake. This setup keeps bad actors off your outer network perimeter.

Still, a tunnel only acts as a blind pipe for network bytes. Once the port opens, the SSH server does not inspect the traffic inside. If a user forwards a database port, SSH sees only raw TCP packets. It cannot read the database queries or check what rows return.

SSH Tunneling Security + VNC Secure Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native SSH rules decide who logs in, not what commands run inside the pipe. An engineer with a valid tunnel can still run a bad query by mistake. They can pull sensitive tables full of customer emails, phone numbers, or card numbers. The bastion log shows that a tunnel opened, but not what data left. Teams need controls that inspect individual commands and mask sensitive fields in flight.

Steps to harden your SSH forwarding rules

Start by moving away from permanent public keys on your target hosts. Set up a central signing key to issue short-lived OpenSSH user certificates. Always define a short validity period every time you sign a key. Attach clear identity strings so your system logs show who owns each session.

Next, lock down the forwarding options inside the certificate and server settings. Only allow port forwarding on the specific hosts that truly need it. Disable agent forwarding and remote port binding when users only need local ports. Restrict the destination hosts and ports that a tunnel can reach. Finally, pair your network rules with tools that check commands at the protocol level.

Inspect one-shot SSH commands and file tasks

SSH certificates and host rules decide who is allowed on a machine. Setup alone does not check single commands or block sftp reads on sensitive paths. By design, hoop.dev runs an open-source SSH listener on the host where people and agents keep their normal ssh, sftp, and scp tools.

First, hoop.dev guardrails check one-shot commands and file paths before they run. Next, hoop.dev data masking masks matched values in file downloads. The audit trail logs the certificate principal, requested action, and verdict without storing session content. Interactive shells carry no guardrails and can be turned off when every action must be checked. Explore the code on GitHub.

Frequently asked questions

How do OpenSSH certificates differ from TLS certificates?

OpenSSH uses its own custom certificate format instead of the X.509 standard. It is much simpler and built just for user and host logins. It stores a public key, identity tags, principal names, and signed options.

Do OpenSSH certificates expire on their own?

No, an OpenSSH certificate stays valid forever unless you set a time window. You must define a start and end time when signing the key. Short validity windows reduce the risk of lost or stolen keys.

Can an SSH bastion see queries inside a database tunnel?

No, a standard SSH bastion only forwards encrypted network packets between ports. It logs when the connection starts and stops, along with the user identity. It cannot read, block, or mask the database queries travelling inside that tunnel.

The query runs. The emails stay hidden.