I am new here but I wanted to share my setup in case its useful to others. I have been using the Cloudflared App for some time now to connect to Frigate and other services running on both of my TrueNAS SCALE servers. I have been pretty happy with it, but the one thing I was really hoping for was to utilise the SSH tunnel functionality of Cloudflared so that my two servers could backup to each other. Previous attempts of doing this have failed, but I have now been able to make it work, meaning that my two servers can securely replicate without needing to do be on the same network or exposed to the internet in a nasty way behind a NAT or port forwarded router.
To do this I used the existing cloudflared app (I have mine with the host network option turned on), and I also created a new app from YAML based on it. You need both. One for connecting out to cloudflare, and one for coming back.
services:
cloudflared:
cap_drop:
- ALL
command:
- access
- tcp
- '--hostname'
- othernas-ssh.example.com
- '--url'
- 0.0.0.0:2222
deploy:
resources:
limits:
cpus: '2'
memory: 4096M
environment:
GID: '568'
GROUP_ID: '568'
HOME: /tmp
NO_AUTOUPDATE: 'true'
NVIDIA_VISIBLE_DEVICES: void
PGID: '568'
PUID: '568'
TUNNEL_SERVICE_TOKEN_ID: <SERVICE-TOKEN-CLIENT-ID>.access
TUNNEL_SERVICE_TOKEN_SECRET: <SERVICE-TOKEN-SECRET>
TZ: Etc/UTC
UID: '568'
UMASK: '002'
UMASK_SET: '002'
USER_ID: '568'
group_add:
- 568
healthcheck:
disable: True
image: cloudflare/cloudflared:latest
platform: linux/amd64
ports:
- '2222:2222'
privileged: False
restart: unless-stopped
security_opt:
- no-new-privileges=true
stdin_open: False
tty: False
user: '568:568'
The above is the yaml for my custom app. it creates a service running on your TrueNAS server on port 2222 that we will use to connect our SSH to and route ourselves through to the other server via Cloudflare. you will need to change 3 things:
hostname: the domain name you have set up in cloudflare to point to your other servers ssh server. If the other server is running the cloudflared app, then navigate to your tunnel in the Cloudflare dashboard and create the public route and point it atssh://127.0.0.1:22service-token-client-id+secret: navigate to your Cloudflare dashboard and go to Zero Trust > Access Controls > Serivce credentials. Create a new service token. Copy the client-id (including the.accesssuffix) and secret and paste them into the correct environment variables
After you have the service running, the only thing left to do in cloudflare is set up an application and policy so that your service token can connect to your ssh endpoint.
- Navifate to Zero Trust > Access controls > Applications.
- Create a new application
- set the sub domain and domain to match your hostname above
- create a new access policy
- Set the action (on the right side) to be Service Auth
- Set the Include to be a Service Token and select the token you created earlier
- Click Save and Save again
The only final thing to do is setup the SSH in your Truenas instance. This is as simple as setting the host to 127.0.0.1 and the port to 22. All of the other configuration around usernames and private keys are the same as any other SSH set up so I won’t go into them here.
If you want both servers replicating to each other, you need to go through the same steps for the other server. I recommend two different service accounts in your Cloudflare dashboard (one for each server) for the best security.
Hopefully that helps others wanting to use Cloudflare tunnels for SSH replication tasks. For my part this means I can move my servers between sites and not have to reconfigure my replication settings. Best of luck to others.




