Opening an SSH port to the internet means one more door to guard. Cloudflare Tunnel flips the direction: the server connects out to Cloudflare, not the other way around, so there is no inbound port to open. Cloudflare Access adds a login layer before traffic reaches the server. This guide walks through the whole setup from scratch, with screenshots at every step. Estimated time: 15-20 minutes.
Privacy note: the screenshots in this post are redacted. Domains, IPs, account names, and tunnel tokens are masked.
What you need
- A Cloudflare account with an active domain (example:
example.com) - A Linux server with
sudo -
cloudflaredon the server (install command in step 7) - A browser for the Cloudflare Access login
Example: this guide uses
ssh.example.comand local port13932. Replace them with your own domain and port.
1. Create an app in Zero Trust
Start with the application you want to protect. In Cloudflare, this app is the front door before traffic reaches your server.
Go to Zero Trust > Access controls > Applications, then click Create new application.
2. Choose the Self-hosted app type
There are several app types here; for SSH we use the self-hosted path.
In the Add an application dialog, select Self-hosted and private, then click Continue with Self-hosted and private. The SaaS applications, Infrastructure, and Bookmarks tabs are for other scenarios, so skip them for now.
Note: Self-hosted and private is for internal services such as SSH. If you are exposing a SaaS app, use the SaaS applications tab instead.
3. Set the domain and Access policy
Next we choose the public address and who is allowed in.
Fill in Subdomain ssh-demo and Domain example.com; leave Path at the default (/). Under Access policies, add an Allow policy for your email. Only addresses in that policy can connect.
Tip: one app can have multiple policies. Allow grants access; Deny always wins.
4. Open the Tunnels page
Tunnels live under Networking, not under the Access app page.
Go to Networking > Tunnels in the Cloudflare sidebar, then click Create Tunnel. A tunnel is an outbound connection from your server to Cloudflare's network.
5. Name the tunnel
Pick a recognizable name, such as ssh-demo, then click Create Tunnel. This is only a dashboard label; the public hostname is configured in step 8.
6. Allow the local port
Check the server firewall with sudo ufw status verbose. The port you will use (for example 13932) must show ALLOW IN. If it does not, open it:
sudo ufw status verbose
sudo ufw allow 13932/tcp
Note: if your server uses firewalld, iptables, or a cloud security group, open the same port there too.
7. Choose the OS and copy the install commands
Cloudflare generates install commands for your server's operating system.
Choose the Operating System and Architecture (for example Linux, amd64), then copy the two commands: Install cloudflared and Install as service. The token in the second command is a secret, so do not share it.
8. Add a route to the local service
Open the tunnel you just created, go to the Routes tab, then click Add a route > Published application. This maps the public hostname to the service running on your server.
Set the hostname to ssh.example.com and the Service URL to ssh://localhost:13932. The Published application route type exposes a local service through a hostname.
Click Add route to save. If your local port is different, change the number in the Service URL.
9. Verify the route
Once saved, the route appears in the list.
Check the hostname, the Published application type, and the Service URL before moving on.
10. Check the cloudflared version
On the server, run cloudflared --version. If it prints a version (for example 2026.10.7), cloudflared is installed and ready.
11. Install cloudflared as a service
Copy the Install as service command from the dashboard and run it on the server. On success you will see Linux service for cloudflared installed successfully.
Important: the token in the Install as service command is a tunnel credential. Do not commit it to a repo or share it.
12. Confirm the tunnel is connected
Once the service is running, Cloudflare shows the tunnel connection status.
Back in the dashboard, the status should switch to Tunnel connected successfully. If it is still Waiting, check the service on the server (step 11).
13. Check that the tunnel is Healthy
The tunnel list shows whether the connection stays healthy.
The tunnel should show Healthy with one replica. In this example ssh-demo has one app (route) and version 2026.10.7.
14. Configure the SSH client
The last step on the client side: tell SSH how to reach that hostname.
On your local machine, add a Host block to ~/.ssh/config. The key line is ProxyCommand cloudflared access ssh --hostname %h; HostName, User, and IdentityFile depend on your server.
Host my-server
HostName ssh.example.com
User ubuntu
IdentityFile ~/.ssh/id_ed25519
ProxyCommand cloudflared access ssh --hostname %h
Note: on macOS and Linux the file lives at
~/.ssh/config; on Windows it is%USERPROFILE%\.ssh\config.
15. Try the SSH connection
Time to test from your local terminal:
ssh my-server
Use the Host name from your config. If the configuration is right, SSH calls cloudflared and opens your browser.
16. Approve access in the browser
Cloudflare Access asks for approval before the connection is forwarded.
The browser opens the Access Requested page. Click Approve, and the SSH session connects. You only need to approve once per browser session.
Done
Your server is now reachable over SSH without opening a port to the internet, and every connection goes through Cloudflare Access.
Other services
The same pattern works for any service running on a server or laptop. Only the Service URL changes when you create the route:
Web app http://localhost:3000
REST API http://localhost:8080
PostgreSQL tcp://localhost:5432
MySQL tcp://localhost:3306
Redis tcp://localhost:6379
RDP rdp://localhost:3389
SSH ssh://localhost:13932
The steps stay the same: start the service, allow the port in the firewall, then add a route with the Service URL above. For non-HTTP services such as databases and RDP, Cloudflare still forwards the TCP connection through the tunnel hostname.
Note: keep databases and RDP behind an Access policy. Do not expose a database port publicly without authentication.
Expose localhost temporarily
If you only need to share a service running on your laptop for a few minutes, you have two options. Both live only while the laptop is on and the cloudflared process is running.
Option 1: Quick tunnel (random domain, no login)
A quick tunnel is the fastest route: one command, no Cloudflare login, a random public URL, and the tunnel dies when the process stops. If cloudflared is not installed on the laptop yet, install it first:
# macOS
brew install cloudflared
# Linux Debian/Ubuntu (amd64; use arm64 for ARM)
BASE=https://github.com/cloudflare/cloudflared/releases/latest/download
curl -L -o cloudflared.deb "$BASE/cloudflared-linux-amd64.deb"
sudo dpkg -i cloudflared.deb
Then start the quick tunnel from your project folder:
cloudflared tunnel --url http://localhost:3000
Replace 3000 with your web app's port. The command prints a URL like https://random-words.trycloudflare.com. Open it from another device while the terminal is still running. This tunnel only lives while the laptop is on and the cloudflared process has not been stopped. There is no Access login page in front of it.
Because there is no authentication, anyone with the link can reach your service. Share it only with people you trust, and stop it with Ctrl+C when you are done. If the laptop sleeps, the terminal closes, or the connection drops, the URL stops working.
Important: do not use a quick tunnel for databases, SSH, admin panels, or services that store sensitive data. Use a permanent tunnel with an Access policy for those, as in steps 1-16.
Option 2: Your own domain (Cloudflare account required)
If you want a stable URL such as dev.example.com, create a named tunnel. This option needs a domain that is active on Cloudflare, but the tunnel can still run temporarily from your laptop.
In Zero Trust > Networking > Tunnels, create a new tunnel, for example laptop-dev.
Open Routes > Add route > Published application. Set the hostname to dev.example.com and the Service URL to http://localhost:3000.
Copy the tunnel token from the install page, then run it on the laptop:
cloudflared tunnel run --token <TOKEN>
Open https://dev.example.com while the terminal is running. Without an Access application, this URL is public; to restrict it, create an Access application for dev.example.com as in steps 1-3.
Use a separate tunnel for the laptop instead of the server token. The tunnel still stops when the laptop sleeps, the terminal closes, or you press Ctrl+C.
Troubleshooting
-
Tunnel is not Healthy: check
sudo systemctl status cloudflaredandjournalctl -u cloudflared -n 50. - SSH connection refused: verify the Service URL and local port, and make sure the port is allowed in the firewall.
- Access denied: make sure your email is in the app's Allow policy.
-
Browser does not open: run
cloudflared access ssh --hostname ssh.example.commanually.
















Top comments (0)