自动摘要
正在生成中……
先在 cloudflare dashboard创建一条隧道

选择cloudflared

完成后复制会得到一个 TUNNEL_TOKEN

就是eyhy...
那一串,复制并保存好。
新建一个容器编排:
compose.yml
内容如下:
services:
cloudflared_ssh:
image: cloudflare/cloudflared:latest
container_name: cloudflared_ssh
restart: unless-stopped
command: tunnel run
volumes:
# 挂载隧道凭据文件
- ./cloudflared:/etc/cloudflared
environment:
# 设置你的隧道 ID 和其他环境变量
TUNNEL_TOKEN: "<上面得到的TUNNEL_TOKEN>"
network_mode: "host" # 推荐 host 模式以支持 SSH 直接监听主机的 22 端口
启动后回到 cloudflare dashboard编辑 Public Host Name Page

如果我在此处使用 ssh.example.com
,在客户机也就是要连接到这个ssh服务器的机器上,除了要先安装cloudflared外。
要修改 ~/.ssh/config
Host example
HostName ssh.example.com
User ssh-user-name
Protocol 2
ServerAliveInterval 10
ServerAliveCountMax 5
#IdentityFile ~/.ssh/your_id_rsa
ProxyCommand cloudflared access ssh --hostname %h
最重要的一条指令是
ProxyCommand cloudflared access ssh --hostname %h
然后你就可以使用ssh example
登录到主机了