Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active October 14, 2021 18:22
Show Gist options
  • Save SomajitDey/a8ce8af891f753307019f52fd45ca200 to your computer and use it in GitHub Desktop.
Save SomajitDey/a8ce8af891f753307019f52fd45ca200 to your computer and use it in GitHub Desktop.
Get free public URL / IP with ngrok

ngrok how to (tested with Linux and WSL)

  1. Download

  2. Sign-up (email is not verified!)

  3. Get your authtoken from the dashboard

  4. ./ngrok authtoken <your authtoken>
  5. Start an online ngrok process in the background:

    ./ngrok tcp -region <your region e.g. in> <local port number> </dev/null &>/dev/null & # For SSH (default port: 22) and nc
  6. Get the public URL and forwarded port to reach your exposed localhost at the local port number given above:

    curl --silent --fail http://127.0.0.1:4040/api/tunnels | grep -o tcp://[^\"]*

    The output would be in the form: tcp://URL:PORT

Quick test with nc

Do all the above. Then open two terminals side by side. In one of them do:

nc -lk <local port number>

In the other, do:

nc <URL> <forwarded port number>

Enter any text in any of the two terminals. The entered text should appear at the other terminal.

Persistent remote access with SSH

  1. Start an online ngrok process at the remote host (viz. the SSH server). To make it persistent, use an infinite loop:

    while :;do ./ngrok tcp 22; done </dev/null &>/dev/null &
  2. In order to SSH to the remote host, simply get the URL and forwarded port from the dashboard.

  3. Connect:

    ssh <your username at the remote host>@<URL> -p <forwarded port number>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment