-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 thebasic-auth-policy.yml file:
--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 theoauth-policy.yml file:
--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:- Mac OS
- Linux
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+xJVKMtcsZL3cqiuY7iYpoxLNg1k5Pqdf2gconnect.us.ngrok-agent.com:SHA256:WuVeeGNOGVrcMe/GcdsTUB135MFCe1/aaVYXrpCxSEM
Command syntax
ngrok does its best to honor the syntax ofssh -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:
ssh -R command has the following components:
- 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 use0, 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 commonlylocalhost. - 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 eitherhttp,tls, ortcp. 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--helpflag 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 isv2.
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:- Your endpoints won’t automatically reconnect if there is a network interruption
- There is no equivalent to the agent’s traffic inspection interface
- You can’t create endpoints for multiple services with the same command
- You can’t forward to upstream HTTPS services
- You can’t create multiple endpoints over the same connection
- You can’t serve file system directories with the
file://protocol - You can’t terminate TLS at the agent when using end-to-end encryption