connect command launches the Terminal User Interface (TUI) connected to a running Surge server, either local or remote.
Usage
Description
Connects the Surge TUI to a running server daemon. The command:- Auto-detects locally running servers when no target is specified
- Connects to remote servers via HTTP/HTTPS API
- Provides full TUI functionality for remote download management
- Supports secure HTTPS connections for remote hosts
- Validates connection and authentication before starting TUI
This command is a convenience wrapper for remote TUI mode. It’s equivalent to running
surge --host <host:port>.Arguments
Target server address in Can also use full URLs:
host:port format. If omitted, auto-detects a locally running server.Examples:Flags
Allow plain HTTP connections for non-loopback targets. By default, remote servers require HTTPS for security.Example:
Examples
Auto-Detect Local Server
Start server:Connect to Localhost
Connect to Remote Server
Using HTTPS (recommended):With Environment Variables
Set once:Connection Modes
Local Auto-Detection
When no target is specified,surge connect reads the port from:
surge and surge server commands.
HTTP vs HTTPS
| Target Type | Default Scheme | Override |
|---|---|---|
localhost / 127.0.0.1 | HTTP | Use full URL |
| Private IP (192.168.x.x, 10.x.x.x) | HTTP | Use full URL |
| Remote hostname/IP | HTTPS | Use --insecure-http |
| Full URL provided | Use scheme from URL | N/A |
Authentication
Token Resolution
Tokens are resolved in this order:--tokenflagSURGE_TOKENenvironment variable- Local token file (for localhost/same machine only)
Local Servers
For localhost connections, the token is automatically read from:--token:
Remote Servers
Remote connections require explicit authentication:TUI Features
When connected, the TUI provides:- Real-time download progress
- Add/remove downloads
- Pause/resume controls
- Live event stream from server
- Full keyboard navigation
- Settings management (reads from remote server)
The TUI operates in remote mode - all actions are sent to the server via HTTP API.
Error Handling
No Local Server
Connection Failed
Authentication Failed
HTTPS Required
Use Cases
Monitor Remote Downloads
Connect to a headless server to monitor downloads:Multiple Terminals
Run server in one terminal:SSH Port Forwarding
Securely connect to remote server:Container/Docker
Connect to Surge running in a container:Network Configuration
Firewall Rules
For remote connections, open the port:Reverse Proxy
For HTTPS support, use nginx or caddy: Nginx:Comparison with —host Flag
These are equivalent:surge connect is a dedicated command for clarity, while --host can be used with the main surge command.
Related Commands
- surge - Main command (can use
--hostfor remote mode) - surge server - Start headless server
- surge token - Get authentication token
- surge add - Add downloads to connected server