xdg-remote-open
Open URLs in your local browser when working on a remote machine via SSH.
Problem
When connected via SSH to a remote server, running xdg-open https://example.com attempts to open the URL on the remote machine rather than your local machine. This often fails because remote servers typically lack a graphical environment. This tool solves that by forwarding URLs to open in your local browser.
How it works
-
Server - Runs on your local machine. It listens for HTTP requests and opens URLs in your local browser.
-
Client - Runs on the remote machine. Sends an HTTP POST request to the server with the URL to open.
Usage
1. Start the server (on your local machine)
xdg-remote-server -token-file /path/to/tokenThe server listens on port 8787 by default. Use -addr to change the address.
2. SSH with port forwarding
ssh -R 8787:localhost:8787 user@remoteThis forwards port 8787 on the remote machine to port 8787 on your local machine.
3. Use from remote machine (via SSH)
xdg-remote-client https://example.com -server-url http://localhost:8787 -token-file /path/to/tokenSetup
-
Build the binaries:
go build -o xdg-remote-server ./cmd/server go build -o xdg-remote-client ./cmd/client
-
Create a token file (used for authentication):
mkdir -p ~/.config/xdg-remote echo "your-secret-token" > ~/.config/xdg-remote/token
-
Copy
xdg-remote-serverto your local machine andxdg-remote-clientto the remote machine. -
Start the server on your local machine.
-
SSH with port forwarding:
ssh -R 8787:localhost:8787 user@remote -
From SSH, use the client to open URLs in your local browser.
Setting up the client as your default xdg-open
Most remote hosts already have an xdg-open command. To intercept URL-opening requests and forward them to your local browser, install the wrapper script:
# On the remote machine
mkdir -p ~/.local/bin
cp xdg-remote-client ~/.local/bin/
cp scripts/xdg-open.sh ~/.local/bin/xdg-open
chmod 700 ~/.local/bin/xdg-openTo ensure the new xdg-open takes precedence, update your PATH in .bashrc or .zshrc:
export PATH=~/.local/bin:$PATHNow any program that calls xdg-open will open URLs in your local browser instead.
Options
Server
-addr- Address to listen on (default::8787)-token-file- Path to file containing bearer token (required)-debug- Enable debug logging
Client
-server-url- Server HTTP URL (default:http://localhost:8787)-token-file- Path to file containing bearer token (required)<url>- URL to open in the browser (positional argument, required)
Security
The server uses bearer token authentication. Set appropriate permissions on the token file:
chmod 600 ~/.config/xdg-remote/token