I have a Rasperberry Pi 2, and i put it in my home in the silent. Sometimes I need to ssh to my Pi or view a website that I deployed to my Pi. I looked for a solution in the Internet. I found Ngrok. I really fitted my case. So in this post, I will share you the way to setup Ngrok on Rasperberry Pi in step by step.
Download Ngrok
You find the correct link to download at https://ngrok.com/download. You see “Linux ARM” and get the link.
After that, you do some commands to download and decompress:
1 2 3 4 5 |
cd /opt mkdir ngrok cd ngrox wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip unzip ngrok-stable-linux-arm.zip |
Creating Configuration File for Ngrok
We need to publish two tunnels (ssh, http). So we have to create a Ngrok configuration file to declare those services.
I create a file named ngrok.yml with content as below
1 2 3 4 5 6 7 8 9 |
web_addr: 0.0.0.0:4040 tunnels: ssh: proto: tcp addr: 0.0.0.0:22 http: proto: http addr: 0.0.0.0:80 auth: username:pass |
web_addr: 0.0.0.0:4040
means that I can access Ngrok Webpage on my Pi via http://RASPERBERRY_PI_IP_ADDRESS:4040
I also declare two protocols and address for two tunnels – SSH and HTTP
Installing Supervisor
We need run Ngrok as a daemon (in background). So I use Supervisor – a third-party process manager. You can install Supervisor with command.
1 |
apt-get install supervisor |
After finishing the installation, we create a Supervisor configuration file at /etc/supervisor/config.d/ngrok.conf with content as below
1 2 3 4 |
[program:ngrok] command=/opt/ngrok/ngrok start http ssh -log stdout --authtoken YOUR_NGROK_TOKEN_HERE -config=/opt/ngrok/ngrok.yml stdout_logfile=/var/log/ngrok.out.log stderr_logfile=/var/log/ngrok.err.log |
Running the tunnels
In this step, we just need to run the program via Supervisor by command:
1 2 |
supervisord reread supervisor start ngrok |
Verifying your works
Now, we open the browser and access http://PI_IP_ADDRESS:4040 to get the information of tunnels and try a test.