# Remote Access — VNC Studio via Cloudflare

# Remote Access — VNC Studio via Cloudflare

## Prerequisites

- `cloudflared` installed on both Studio and Air
- Screen Sharing enabled on Studio: **System Settings → General → Sharing → Screen Sharing**
- Cloudflare Tunnel "mattermost" running on Studio (LaunchAgent: `com.john.cloudflared`)

---

## Architecture

```
Studio: macOS Screen Sharing (VNC :5900)
    → Cloudflare Tunnel
    → vnc.basicconsulting.no
    → Air: cloudflared TCP proxy
    → localhost:5901
    → Finder VNC client
```

- **Studio** exposes VNC on port 5900 (macOS Screen Sharing)
- **Cloudflare Tunnel** proxies TCP traffic to `vnc.basicconsulting.no`
- **Air** runs a local `cloudflared` proxy that maps tunnel → `localhost:5901`
- Port 5901 on Air avoids conflict with Air's own Screen Sharing (5900)

---

## Studio Setup (One-time — already done)

Cloudflared config (`~/.cloudflared/config.yml`) includes:

```yaml
- hostname: vnc.basicconsulting.no
  service: tcp://localhost:5900
```

Tunnel runs as a LaunchAgent:

```bash
# Check tunnel status
launchctl list com.john.cloudflared

# Restart if needed
launchctl kickstart -k gui/$(id -u)/com.john.cloudflared
```

---

## How to Connect from Air

1. Open Terminal on Air

2. Start the local TCP proxy:
```bash
cloudflared access tcp --hostname vnc.basicconsulting.no --url localhost:5901
```

3. Open Finder → **Go → Connect to Server** (`Cmd+K`)

4. Enter:
```
vnc://localhost:5901
```

5. Enter the VNC password when prompted

> Keep the Terminal window open — the `cloudflared` proxy must stay running for the session.

---

## Troubleshooting

**Connection fails:**
```bash
# On Studio — verify tunnel is running
ps aux | grep cloudflared

# Restart tunnel on Studio
launchctl kickstart -k gui/$(id -u)/com.john.cloudflared
```

**Lag / slow display:**

Display is at 2560x1440 (5K scaled). Reduce resolution temporarily to improve performance:

```bash
# Reduce to 1080p (lower lag)
displayplacer "id:D8EAE737-E4F0-42D1-9AD0-C39CDD691C67 res:1920x1080 hz:60 color_depth:8 scaling:on enabled:true"

# Restore original resolution
displayplacer "id:D8EAE737-E4F0-42D1-9AD0-C39CDD691C67 res:2560x1440 hz:60 color_depth:8 scaling:on enabled:true"
```

**Port conflict on Air:**

If port 5901 is already in use:
```bash
lsof -i :5901
```
Use a different port (e.g. 5902) and update the `vnc://` address accordingly.

---

## noVNC (Browser fallback — NOT recommended)

Tested and unusable due to lag on 5K display. Documented here for reference only.

**Install:**
```bash
pip3 install --break-system-packages websockify
git clone https://github.com/novnc/noVNC.git ~/novnc
```

**Run (on Studio):**
```bash
websockify --web ~/novnc 6080 localhost:5900
```

**Access:** https://remote.basicconsulting.no/vnc.html?resize=scale

**Verdict:** Unusable lag at 5K resolution. Use the `cloudflared` TCP method above.

---

*Last updated: 2026-02-24*
*Created by: John — post VNC remote access session*