THE PAIN POINT
What led me into using Ngrok on my linux machine? So, I made some changes on my local linux machine, and then without sending my changes to the remote Github repository, I needed to show my boss who is miles away the changes I made to the application frontend. He asked me for a link. Having to create a fresh URL link from my DNS management console is a little stressful at this point since it is for a temporary use.
That led me to a litte googling, and boom, I found Ngrok. With Ngrok, I can serve my application using a url from Ngrok without altering my existing computer network protocols or even creating any DNS records with my domain provider. That process is call secure ingress tunnelling. Ngrok even allow you to tunnel an existing URL. It is the easiest solution to my pain point.
So, we will configure Ngrok on linux for our application.
First, we will register an account on the Ngrok website at ngrok.com. Select the Signup option and supply the name, email, and a strong password for your account. Select the Checkbox to accept the terms and condition. Click on the signup button.
Ngrok will send a verification email to the inbox of the email address you supplied. So, head to your email inbox to find the verification email. I recommend you copy and paste the link in another browser for the verification.
In the new tab, you will find the Ngrok authtoken and some more informations about your account on your Dashboard.
Install Ngrok on Linux
Now, let’s go to our machine’s command-line interface, there we will download and install the Ngrok package. The command below will download the Ngrok package to Ubuntu machine. You can find the link to download Ngrok packages on Linux here. However, instead of clicking the Download button, copy the link address and paste in your machine.
sudo wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
Then, extract the Ngrok linux package into the /usr/local/bin directory
sudo tar xvzf ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin
You can check if Ngrok is installed on your machine.
You can also install Ngrok on Linux from the apt package.
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
Or the snap package. Though I do not recommend this due to the security vulnerability that comes with snap packages.
snap install ngrok
ADD AUTH TOKEN
Next, you should add the Ngrok auth token. Copy the token from your dashboard and paste in your command line.
ngrok config add-authtoken your_auth_token
tunnel your application port with Ngrok
Now that we have install Ngrok on Linux machine, and added the authentication too, we can go ahead to tunnel our application using the port number. The port of my application is 5665. Yours could be different.
ngrok https 5665
Now, grab the ngrok URL from your Linux machine and paste in the browser to view your application. Since you are using Ngrok on linux for the first time, you will be asked to confirm if you want to visit the site.
Once you confirm that, the Ngrok URL will serve your site.
checkout the logs
You can check out the logs of your URL from the command line or the web browser with the Ngrok port 4040 appended to your machine’s IP address
There you are, you can repeat this steps as many times as you want to tunnel your application to serve using Ngrok on linux.