ngrok is a command-line tool that works on Linux, Windows, and Mac, allowing you to publish websites, web services, and web applications in the development stage from your local environment to the internet, making them accessible to anyone.
<>
With ngrok, you can

This article will explain in detail the installation method, usage, and security measures for ngrok.
Installing ngrok
There are three ways to install ngrok. However, only one method succeeded in my environment. The last command is that method. Also, the third method is recommended as it’s the least likely to encounter errors mentioned later.
# Install with npm
sudo npm install ngrok -g
# Install with apt
sudo apt update ; sudo apt-get install ngrok-client
# Direct installation
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
When installed with npm or apt, the ngrok command path is added, so you can execute it with the ngrok command.
When using directly installed ngrok, you can execute commands in the form of ./ngrok to run the extracted executable file.
If you want to manually download ngrok, you can do so from the following:
The wget above downloads the “Linux” wget file. This file should work for most Linux machines. Other distributions and operating systems are as follows:
<>
- Mac OS X
- Linux
- Mac (32-bit)
- Windows (32-bit)
- Linux (ARM)
- Linux (ARM64)
- Linux (32-bit)
- FreeBSD (64-Bit)
- FreeBSD (32-bit)
ngrok Command Options
Running ngrok —help allows you to check the list of options. Let’s see if there are any options you want to use.
yuis ASUS /mnt/c/_tmp/20200109023429$ ./ngrok --help
NAME:
ngrok - tunnel local ports to public URLs and inspect traffic
DESCRIPTION:
ngrok exposes local networked services behinds NATs and firewalls to the
public internet over a secure tunnel. Share local websites, build/test
webhook consumers and self-host personal services.
Detailed help for each command is available with 'ngrok help <command>'.
Open http://localhost:4040 for ngrok's web interface to inspect traffic.
EXAMPLES:
ngrok http 80 # secure public URL for port 80 web server
ngrok http -subdomain=baz 8080 # port 8080 available at baz.ngrok.io
ngrok http foo.dev:80 # tunnel to host:port instead of localhost
ngrok http https://localhost # expose a local https server
ngrok tcp 22 # tunnel arbitrary TCP traffic to port 22
ngrok tls -hostname=foo.com 443 # TLS traffic for foo.com to port 443
ngrok start foo bar baz # start tunnels from the configuration file
VERSION:
2.3.35
AUTHOR:
inconshreveable - <[email protected]>
COMMANDS:
authtoken save authtoken to configuration file
credits prints author and licensing information
http start an HTTP tunnel
start start tunnels by name from the configuration file
tcp start a TCP tunnel
tls start a TLS tunnel
update update ngrok to the latest version
version print the version string
help Shows a list of commands or help for one command

Authenticating a Token with ngrok
Using ngrok without a token means some options like basic authentication won’t be available. You can use it without obtaining a token, but it’s recommended to get one.
You can obtain a token from the following. First, create an account. It’s free.
ngrok - secure introspectable tunnels to localhost

Next, check the token on the following page.
ngrok - secure introspectable tunnels to localhost
Finally, execute the following command. Replace [token] with the obtained token string.
./ngrok authtoken [token]
# e.g. ./ngrok authtoken k3h53lh6ll34k5
When token registration completes successfully, it will display as follows.
Authtoken saved to configuration file: /home/yuis/.ngrok2/ngrok.yml
How to Use ngrok
Let me explain how to use ngrok.
For example, if you’re running a site on port 8111, localhost:8111, and want to access this site from the internet, the command would be as follows.
./ngrok http -auth="user:pw" 8111
If you have a local environment site like the following,

You can access it from the internet as follows.

The command line displays statistical information as follows. To terminate this, type ctrl-C.

Common ngrok Errors
Here’s a summary of common errors you’re likely to encounter while using ngrok.
You may only specify one port to tunnel to on the command line, got 2
This “You may only specify one port to tunnel to on the command line, got 2” error appears to occur in the following situation.
This means you’re trying to run an ngrok2 command with the older ngrok1 client. Either use the old syntax for an ngrok1 client ngrok 80 or make sure you grab the latest ngrok from https://ngrok.com/download
What this error means is that you’re trying to run an ngrok2 command with the old ngrok1 client. To resolve this error, use a command with syntax compatible with ngrok1, or download and use the latest ngrok from the link below.
use ./ngrok http 80
Use the ./ngrok http 80 command.
You may only specify one port to tunnel to on the command line, got 2 · Issue #304 · inconshreveable/ngrok You may only specify one port to tunnel to on the command line, got 2 - Google Search
If you installed with wget, you shouldn’t encounter this error. If you installed with other methods, try the installation method mentioned earlier.
You may only specify one port to tunnel to on the command line, got 2
'ngrokd.ngrok.com:443': lookup ngrokd.ngrok.com: no such host
Failed to bind a tunnel with HTTP authentication for an unauthenticated client.
This error occurs when trying to add basic authentication to ngrok without registering a token.
$ ./ngrok http -auth="user:password" 8111
HTTP auth is only available after you sign up.
Failed to bind a tunnel with HTTP authentication for an unauthenticated client.
Sign up at: https://ngrok.com/signup
If you have already signed up, make sure your authtoken is installed.
Your authtoken is available on your dashboard: https://dashboard.ngrok.com
ERR_NGROK_304

Services Similar to ngrok
There’s a tool called localtunnel that I’ve introduced several times on this blog.
localtunnel/localtunnel: expose yourself
If the ngrok introduced this time doesn’t work well, I recommend trying localtunnel.
Summary
I introduced ngrok, a command-line tool that works on Linux, Windows, and Mac, allowing you to publish websites, web services, and web applications in the development stage from your local environment to the internet, making them accessible to anyone.
The installation method for ngrok is very simple. The usage is also relatively simple, and account creation is optional. Security measures using basic authentication are also possible.
ngrok is a useful tool for testing sites in the development stage. Please use it in your future programming and service development.