Skip to main content
A reverse SSH tunnel uses SSH’s -R flag to expose a service running on your local machine through a remote server, so it can be reached from outside your network without opening inbound ports. ngrok supports this pattern directly: SSH reverse tunneling (ssh -R) is an alternative mechanism to deliver services via ngrok without running an ngrok agent or SDK. The SSH reverse tunnel agent shouldn’t be confused with creating remote access to an SSH server via ngrok. If you want to use ngrok to create access to your own SSH server for remote access, see the using ngrok with ssh documentation. Only use ngrok via SSH if you really can’t use an agent or SDK. The SSH reverse tunnel agent has many functional limitations compared to the ngrok agent.

Example usage

HTTP endpoint on your dev domain

Custom domain

Basic Auth

When creating a reverse tunnel, you must provide a publicly accessible URL to your Traffic Policy file. Because anyone with that URL can read the file, store passwords in Vaults and Secrets instead of in the file. First, create the basic-auth-policy.yml file:
Store this file at a publicly accessible address online. For example, you could add it to a GitHub repository. Finally, add your Traffic Policy to your reverse tunnel using the --traffic-policy-url flag.

OAuth

When creating a reverse tunnel, you must provide a publicly accessible URL to your Traffic Policy file, as shown in this example. First, create the oauth-policy.yml file:
Store this file at a publicly accessible address online. For example, you could add it to a github repository. Finally, add your Traffic Policy to your reverse tunnel using the --traffic-policy-url flag.

Forward to non-local service

Random TCP endpoint

Fixed TCP endpoint

TLS endpoint

Explicit region selection

Normally, you connect to ngrok’s closest point of presence via the Global Load Balancer, but you can also explicitly choose a region.

Authentication

Instead of an ngrok authtoken, when you use ngrok via the SSH reverse tunnel agent, it uses a public key for authentication. First, upload yours to the SSH Public Keys page on your ngrok dashboard. Copy your default SSH public key with:
or:

ngrok’s SSH public key fingerprints

You can use public key fingerprints to validate a connection to the ngrok point of presence you’re connecting through. These are the RSA public key fingerprints:
  • connect.ap.ngrok-agent.com: SHA256:K/3UwSeIg0JVf9uLVfl4QLEY11tyON/d+QmLfIU0fmk
  • connect.au.ngrok-agent.com: SHA256:RpCOpodROXqXy4d0SIm7rAqwEUsmmUHA6NAQ6T4EHXY
  • connect.eu.ngrok-agent.com: SHA256:OeywYk1/2w9cOg8Q3FjbsMOe2Hc9CvxbyBhDdUBBOlQ
  • connect.in.ngrok-agent.com: SHA256:acotuxa/+tJY2vmK+VeLQIoVOJLQz/VLTmHTJ/0LPaI
  • connect.jp.ngrok-agent.com: SHA256:/6j2cYqVbjO9YvEKKXTOqHlND72fCms0sdVWClHJAks
  • connect.sa.ngrok-agent.com: SHA256:Wh3W1ub0J/eda2QcEPbrVgS6mdGxIUrbao9G5zMBvdc
  • connect.us-cal-1.ngrok-agent.com: SHA256:UwLN719B+xJVKMtcsZL3cqiuY7iYpoxLNg1k5Pqdf2g
  • connect.us.ngrok-agent.com: SHA256:WuVeeGNOGVrcMe/GcdsTUB135MFCe1/aaVYXrpCxSEM

Command syntax

ngrok does its best to honor the syntax of ssh -R. For more details, see man ssh and its section on the -R option. ngrok uses additional command line options to implement features that aren’t otherwise available via the -R syntax. Consider the following command:
An ssh -R command has the following components:
In this example:
  • Remote Name: app.example.com. ngrok listens on the domain ‘app.example.com’. You may omit this value. If you do, HTTP and TLS endpoints use your account’s dev domain, and TCP endpoints get a random address and port. Free accounts created before September 23, 2025, and some paid plans, get a random hostname for HTTP and TLS endpoints instead.
  • Remote Port: 443. ngrok listens for HTTPS traffic on port 443. The only valid values for HTTP endpoints are 80 and 443. For TLS endpoints, it must be 443. You can use 0, and ngrok chooses the appropriate port for you.
  • Local Name: 127.0.0.1. This is the local hostname or IP address that ngrok sends traffic to. It’s most commonly localhost.
  • Local Port: 8080. This is the local port that ngrok sends traffic to.
  • User: v2. ngrok uses the user portion of the command to version the command options. You may omit this value. If you do, ngrok will use the latest version.
  • Command: http. This is the type of endpoint to create. ngrok accepts either http, tls, or tcp. This value is required.
  • Flags: --traffic-policy-url https://example.com/policy.yml. This applies the Traffic Policy hosted at that URL to the endpoint. Run the same command with the --help flag to get the list of supported flags.

Versioning

ngrok uses the user portion of the SSH command to version the CLI syntax. The latest version is v2.

Differences from the agent

When you use ngrok via SSH reverse tunnel, you upload an SSH public key to authenticate instead of using an ngrok authtoken like the agent. Using ngrok via SSH also has many functional limitations compared to the experience with the agent. An incomplete list of differences from the ngrok agent includes:

SSH reverse tunnel agent pricing

The SSH reverse tunnel agent is available to all ngrok users at no additional charge. You only incur costs if resources you provision via its usage incur a cost. For more information, see the ngrok Pricing page.