wstunnel 是一个基于 WebSocket 的隧道工具,主要优势包括:
相关资料参考官方文档:https://github.com/erebe/wstunnel
# 创建专用目录
mkdir ~/wstunnel && cd ~/wstunnel
# 下载最新版
chmod +x wstunnel
/wstunnel server wss://[::]:1022 --restrict-to 127.0.0.1:22
监听 1022 端口,转发到22端口。
vi /etc/systemd/system/wstunnel.service
创建一个简单的服务:
# /etc/systemd/system/wstunnel.service
[Unit]
Description=wstunnel
After=network.target
[Service]
User=root
ExecStart=/root/wstunnel/wstunnel server wss://[::]:1022 --restrict-to 127.0.0.1:22
ExecReload=/bin/kill -SIGUSR1 $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 重载 systemd
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start wstunnel
# 设置开机自启
sudo systemctl enable wstunnel
# 检查状态
sudo systemctl status wstunnel
我是 M2 芯片,下载 wstunnel_10.4.3_darwin_arm64.tar.gz
解压到合适的位置,赋权:
chmod +x wstunnel
监听本地2222端口,ssh的目的IP和端口是127.0.0.1:22,后面是转发的服务器IP和1022端口
./wstunnel client -L tcp://2222:127.0.0.1:22 wss://<服务器IP>:1022
ssh -p 2222 root@localhost