Home/Glossary/Reverse SSH tunnel

Reverse SSH tunnel

A method for accessing a machine behind a NAT or firewall by establishing an outbound connection to a remote server that forwards incoming traffic back to the client.

A Reverse SSH Tunnel is a networking technique used to grant an external server access to a local machine hidden behind NAT or a restrictive firewall. Instead of the server initiating a connection to the client, the client establishes an outbound SSH session and instructs the server to forward traffic from one of its ports back to the client's local environment.

How it works

The process starts when the target machine executes the ssh -R command. This action opens a listening port on the remote public server. Any traffic arriving at this specific port is encapsulated within the established SSH tunnel and delivered to a designated local port on the target machine. This effectively turns the remote server into a relay, bypassing the need for inbound firewall rules on the client side.

This method is widely used for managing IoT devices, providing remote support to workstations without public IP addresses, and navigating complex corporate network topologies. It eliminates the requirement for manual Port Forwarding on intermediate routers where administrative access might be unavailable.

A practical example involves the command ssh -R 8080:localhost:80 user@public-vps. This allows anyone accessing port 8080 on the public VPS to view a web server running locally on the client. To ensure reliability in production environments, administrators often deploy autossh to monitor and restart the tunnel automatically if the connection drops.