Skip to content

Instantly share code, notes, and snippets.

@oeo
Created February 5, 2026 22:57
Show Gist options
  • Select an option

  • Save oeo/6993e2b7814d1a9ecc67fa66ce318fb9 to your computer and use it in GitHub Desktop.

Select an option

Save oeo/6993e2b7814d1a9ecc67fa66ce318fb9 to your computer and use it in GitHub Desktop.
Setup Cloudflare Tunnel for SSH (WSL2) - No signup required
#!/bin/bash
# Setup Cloudflare Tunnel for SSH access from within WSL2
# Free, no signup required, reliable
# Run this script to create a public SSH tunnel
set -e
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Cloudflare Tunnel SSH Setup (WSL2) ║"
echo "║ No signup required - completely free ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
# Check if running in WSL
if ! grep -q microsoft /proc/version; then
echo "ERROR: This script must be run from WSL2"
exit 1
fi
# Check if cloudflared is installed
if ! command -v cloudflared &> /dev/null; then
echo "[1/3] Installing cloudflared..."
# Add cloudflare gpg key
echo " → Adding Cloudflare repository..."
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
# Add repository
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
# Install
echo " → Installing cloudflared..."
sudo apt-get update -qq
sudo apt-get install -y cloudflared
echo " ✓ cloudflared installed"
else
echo "[1/3] cloudflared already installed ✓"
fi
# Ensure SSH is running
echo "[2/3] Checking SSH service..."
if ! sudo service ssh status | grep -q "running"; then
echo " → Starting SSH service..."
sudo service ssh start
sleep 2
fi
if sudo service ssh status | grep -q "running"; then
echo " ✓ SSH service is running"
else
echo " ✗ SSH service failed to start"
echo ""
echo "Try running: sudo service ssh restart"
exit 1
fi
# Check if SSH is listening on port 2222
if sudo netstat -tlnp 2>/dev/null | grep -q ":2222"; then
echo " ✓ SSH listening on port 2222"
else
echo " ✗ SSH not listening on port 2222"
echo ""
echo "Check SSH config: sudo nano /etc/ssh/sshd_config"
echo "Ensure: Port 2222"
exit 1
fi
# Start cloudflared tunnel
echo "[3/3] Starting Cloudflare Tunnel..."
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Cloudflare will display a URL like: ║"
echo "║ https://[random].trycloudflare.com ║"
echo "║ ║"
echo "║ Share that URL to allow SSH access via: ║"
echo "║ ssh -o ProxyCommand='cloudflared access tcp --hostname %h' taky@[URL] ║"
echo "║ ║"
echo "║ Or the tunnel will show a direct TCP endpoint. ║"
echo "║ Press Ctrl+C to stop the tunnel. ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
echo "Connection details:"
echo " Username: $(whoami)"
echo " Password: oijoij"
echo ""
echo "Starting Cloudflare Tunnel on localhost:2222..."
echo ""
cloudflared tunnel --url tcp://localhost:2222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment