In http://ouyangminwei.com/index.php/2021/09/18/build-a-discrod-music-bot/, I created a discord bot and develop on a Raspberry pi, but now there are two problems
- The network used by is a floating IP.
- Even if I can SSH in, I still can’t see or close the discord bot since It is on a terminal.
Ngrok
After searching a little bit, I found that ngrok can solve the first problem perfectly.
Ngrok is a cross-platform application that exposes local server ports to the Internet, so I can expose my raspberry pi to the internet.
First, sign up and download ngrok on this website https://ngrok.com/.
Because it runs on the Raspberry Pi, so download the 32-Bit ARM’s version

After you download the ngrok upzip it.
unzip ngrok-stable-linux-arm.zip.zip

Login the ngrok, yo can get your Authtoken
./ngrok authtoken

And you are ready to fire it up.
./ngrok tcp 22

remember the Ip it gives you
tcp://2.tcp.ngrok.io:14139
Then you can SSH to it
ssh username@2.tcp.ngrok.io -p14139

Screen
In order to access to running terminal, we can use “screen” to achieve it
sudo apt-get install screen

This can create a new screen call “bot”
screen -mS bot
And you can start your server, for here, I will test will python httpserver
python -m SimpleHTTPServer

Now, the server is running, CTRL+A and then CTRL+D to detach the screen.
screen -ls
Show the screen

I have a “test.root” over here, Try to see if I can download this file via this python http server

wget 127.0.0.1:8000/test.root

Every works well, the server it still running.
screen -x bot
Back to the terminal

So now, I can access the Raspberry pi with ngrok and use screen to control the terimal.

