安装 go

安装地址

环境变量

1
2
3
4
5
6
export GO111MODULE=off
export GOPROXY=https://goproxy.cn
export GOROOT=/usr/local/go #当前自己的golang所在位置
export PATH=$PATH:/usr/local/go/bin::$GOROOT/bin:/usr/local/ngrok/bin
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="ngrok.wuzhaoyi.xyz"

安装 ngrok

1
2
cd /usr/local
git clone https://github.com/inconshreveable/ngrok.git

创建证书

1
2
3
4
5
6
7
8
9
10
11
cd ngrok

openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=ngrok.wuzhaoyi.xyz" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=ngrok.wuzhaoyi.xyz" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

cp rootCA.pem ./assets/client/tls/ngrokroot.crt
cp device.crt ./assets/server/tls/snakeoil.crt
cp device.key ./assets/server/tls/snakeoil.key

编辑ngrok

1
2
make release-server
make release-client

开启服务端

1
ngrokd -domain="ngrok.wuzhaoyi.xyz" -httpAddr=":8800" -httpsAddr=":8443" -tunnelAddr=":4443"  > log.out &

开启客户端

移动服务器 /usr/local/ngrok/bin/ngrok 到 客户机

给予权限

1
chmod 777 ngrok

创建文件

1
2
mkdir ~/ngrok_client
cd ~/ngrok_client

简单配置

1
2
3
#ngrok.cfg
server_addr: "ngrok.wuzhaoyi.xyz:4443"
trust_host_root_cert: false

开启

1
./ngrok -config=ngrok.cfg -log=ngrok.txt 80

同时开启 http https ssh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server_addr: "ngrok.wuzhaoyi.xyz:4443"
trust_host_root_cert: false
tunnels:
http:
subdomain: "www"
proto:
http: "8080"

https:
subdomain: "www"
proto:
https: "3000"

ssh:
remote_port: 2222
proto:
tcp: "22"
1
./ngrok -config ngrok.cfg start http https ssh

连接

连接

1
ssh prajna@ngrok.wuzhaoyi.xyz -p 2222

QA

问题一 reconnecting

1
x509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0

解决方法

添加到.zshrc

1
export GODEBUG=x509ignoreCN=0

关闭进程

1
2
3
lsof -i -P -n | grep  443

kill -9 693