Cloudflare Tunnel + Tabby SSH 架构部署指南
一、 服务端部署 (Linux / Amazon EC2)
1. 安装 cloudflared
使用官方脚本快速安装:
Bash
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
2. 初始化与配置
身份认证:
执行
cloudflared tunnel login,点击生成的 URL 完成授权。创建隧道:
Bash
cloudflared tunnel create my-ssh-tunnel记下生成的隧道 ID(例如:
xxxx-xxxx-xxxx)。编写配置文件 (
/etc/cloudflared/config.yml):YAML
tunnel: xxxx-xxxx-xxxx # 替换为你的隧道 ID credentials-file: /root/.cloudflared/xxxx-xxxx-xxxx.json ingress: - hostname: mootn.mdomain.com service: ssh://localhost:22 - service: http_status:444
3. 配置参数与路径指定
如果你想将配置文件放在自定义路径(如 /opt/my-config.yml),启动时需显式指定:
Bash
cloudflared --config /opt/my-config.yml tunnel run
4. 注册为系统服务 (Systemd)
默认安装:
Bash
cloudflared service install纠错技巧:若需修改服务读取的配置路径,编辑
/etc/systemd/system/cloudflared.service中的ExecStart行,加入--config /你的/路径.yml。启动与自启:
Bash
systemctl enable --now cloudflared
5. 卸载与撤销
停止并删除服务:
Bash
cloudflared service uninstall清理残留文件:
Bash
rm -rf /etc/cloudflared rm -rf ~/.cloudflared rm /usr/local/bin/cloudflared
二、 本地端配置 (Windows + Tabby)
1. 准备工作
从 GitHub 下载
cloudflared-windows-amd64.exe并存放到固定位置(如D:\soft\cloudflared.exe)。重要验证:首次使用前,在本地 CMD 运行以下命令完成设备授权:
PowerShell
"D:\soft\cloudflared.exe" access login https://mootn.mdomain.com
2. Tabby 界面操作配置
新建连接:在 Tabby 中添加一个新的 SSH Profile。
主机设置:
Host:
mootn.mdomain.comUser:
root
配置 Proxy Command:
进入 Connection -> Proxy。
Proxy type: 选择 Command。
Command: 填入以下指令(注意双引号):
Plaintext
"D:\soft\cloudflared.exe" access ssh --hostname %h
三、 安全加固:Cloudflare Access
通过 Access 策略,在 SSH 握手前增加一层身份校验。
初始化:在 Zero Trust 控制台点击 Access -> Get started(选择 Free Plan)。
创建应用:
选择 Self-hosted 类型。
填入对应的域名
mootn.mdomain.com。
设置策略:
在 Policy 页面,设置 Include -> Emails 为你自己的常用邮箱。
效果:当你在 Tabby 发起连接时,浏览器会自动弹出要求你输入邮箱验证码,通过后 Tabby 才能连通。
四、 架构维护建议
日志排查:服务端报错时查看
journalctl -u cloudflared -f。配置变更:每次修改
config.yml后,必须执行systemctl restart cloudflared才能生效。