How to Install ngrok and configure automatic startup on Ubuntu

I tested ngrok on Ubuntu 22.04. I referred to Linux | ngrok documentation

1. SSH Connection Setup

ssh-keygen
sudo apt-get install openssh-server # for Debian
# sudo yum install openssh-server # for RHEL
/etc/init.d/ssh start


2. Install and Run Ngrok

sudo apt update
sudo apt install snapd
snap install ngrok
ngrok config add-authtoken <your ngrok token>
ngrok tcp 22


3. (Option) Allow Only Specific IPs (below is an example)

ngrok tcp 22 \
  --cidr-allow 110.0.0.0/8 \
  --cidr-allow 220.12.0.0/16 \


4. Start SSHD Automatically at Boot

If you are not using Ubuntu, then execute code below.

sudo systemctl enable ssh.service


5. Start Ngrok Automatically at Boot

You need to indicate the location of the ngrok binary file.
- The shell script should include the full path to the ngrok binary (e.g., /snap/bin/ngrok).
vi start_ngrok.sh
#!/bin/bash
/snap/bin/ngrok tcp 22

Make the script executable by running the following command in the terminal and Open the crontab editor
chmod +x start_ngrok.sh
crontab -e

In the editing window, add the script path to be executed at boot.
- Replace 'user' with your username.
@reboot /home/user/start_ngrok.sh

댓글