How an SSH Tunnel Reaches a Private Service

A service reachable directly from a workstation needs only its network address and port. A service on a private network may require an approved intermediary. Local tunneling over SSH lets an authorized user connect an application to a port on the workstation while a managed SSH server reaches the private service.

Follow the connection

With local forwarding, the SSH client creates a listening port on the client machine. The application connects to that local listener. SSH carries the connection through its encrypted session to the server, and the server opens a separate TCP connection to the specified destination and port. The destination address is therefore interpreted from the SSH server’s network, not the workstation’s.

An SSH tunnel is useful when a managed gateway can reach a private database or web service that the workstation cannot reach directly. The gateway account, forwarding permission, destination, and application access must all be authorized. The destination service still applies its own authentication and access controls.

Set up a local forward

This OpenSSH example connects an authorized workstation to a private web service through a managed gateway:

ssh -N -L 127.0.0.1:18080:service.internal:8080 [email protected]

Replace the example names, account, and ports with the approved values. The parts have distinct jobs:

  • [email protected] identifies the SSH account and server. Verify the server’s host key through the organization’s trusted process before accepting it.
  • 127.0.0.1:18080 creates a listener on the workstation’s IPv4 loopback address. The application connects to this local port.
  • service.internal:8080 is the destination the gateway must resolve and reach. It may be another private host or the gateway itself.
  • -N keeps the session open for forwarding without running a remote command. Keep the terminal session running while using the service; stopping SSH closes the listener and its connections.

The OpenSSH client manual describes -L and the available bind options. The account and server policy must permit forwarding. A local listener can be created even when a later connection to the destination fails, so its existence alone is not a complete test.

Choose the listener’s scope

Binding explicitly to 127.0.0.1 limits this listener to local IPv4 connections. Other users or processes on the same workstation may still be able to connect to that port, subject to local controls. Binding to a network-facing address can make the forwarded service reachable from other machines and should be done only when specifically authorized and protected.

A local SSH port tunnel carries the selected TCP connection; it does not automatically route all workstation traffic through the gateway. The SSH forwarding tunnel encrypts traffic between the client and gateway. The separate gateway-to-service connection needs its own protection when that network or the data requires it. For HTTPS, configure the application to use the service’s expected hostname and validate its certificate; connecting to a loopback address directly can otherwise cause a hostname mismatch.

Verify the path in order

First confirm that the SSH tunneling session authenticated to the intended gateway and remains open. If the client reports that port 18080 is already in use, choose another approved local port and update the application. Check the local listening socket with the operating system’s network tools; for example, ss -ltn on Linux can show the bound address and port.

Next, test the private service from the gateway using an approved diagnostic and the actual destination name and port. If that connection fails, investigate name resolution, routing, firewall rules, and whether the service is listening. If it succeeds but the forwarded connection fails, check the SSH server’s forwarding policy and the client session’s diagnostic messages. Local SSH forwarding may be restricted by account or destination.

Finally, configure the application to use the local endpoint and test an authenticated operation appropriate to the service. A successful TCP connection alone does not establish that application credentials, TLS, or permissions are correct. If the operation fails, use the application error and SSH diagnostics to identify the failing stage, then check that stage’s settings before retrying the SSH tunnel.