SSH to a Linux by ngrok and manipulate existing terminal

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

  1. The network used by is a floating IP.
  2. 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

這張圖片的 alt 屬性值為空,它的檔案名稱為 image-39.png

After you download the ngrok upzip it.

unzip ngrok-stable-linux-arm.zip.zip
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-38.png

Login the ngrok, yo can get your Authtoken

./ngrok authtoken
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-37-1024x556.png

And you are ready to fire it up.

./ngrok tcp 22
解析Ngrok 曲折的攻擊程序– 資安趨勢部落格

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
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-41.png

Screen

In order to access to running terminal, we can use “screen” to achieve it

sudo apt-get install screen
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-40.png

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
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-42.png

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

screen -ls

Show the screen

這張圖片的 alt 屬性值為空,它的檔案名稱為 image-43.png

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

這張圖片的 alt 屬性值為空,它的檔案名稱為 image-44.png
wget 127.0.0.1:8000/test.root
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-45-1024x183.png

Every works well, the server it still running.

screen -x bot

Back to the terminal

這張圖片的 alt 屬性值為空,它的檔案名稱為 image-46.png

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

這張圖片的 alt 屬性值為空,它的檔案名稱為 image-47.png
這張圖片的 alt 屬性值為空,它的檔案名稱為 image-48-1024x157.png

分類: Uncategorized,標籤: , 。這篇內容的永久連結

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *