See Ash Code logo See Ash Code

Keeping a remote browser alive after SSH disconnects

Ashlynn Antrobus
• • 2 min read

Most of my work on the NUC happens over SSH. That lets me move between the desktop, laptop and phone without moving the development machine. It becomes awkward when an OAuth flow needs a browser window.

In October I added a usable remote desktop around the virtual X display I’d started in August. The goal was a browser that kept running on the NUC while I connected and disconnected from it.

A dragon closes a laptop while a server and browser remain lit beyond a broken connection.

The viewer is only one part of the desktop

Xvfb was already running on display :99. It supplied a screen without a monitor, but didn’t give me window management or a way to see that screen from the laptop.

The completed arrangement looked like this:

systemd user manager, with lingering enabled
  └─ Xvfb :99
       ├─ Openbox: window management
       ├─ Chrome: persistent browser profile
       └─ x11vnc: display access on loopback port 5900
            └─ websockify/noVNC: browser viewer on loopback port 6080
                 └─ SSH local forward to the laptop

Chrome and x11vnc need the display to exist. noVNC needs the VNC server. Closing the laptop’s viewer doesn’t remove the display or terminate Chrome.

The first screen was 1920×1080, which was inconvenient on the laptop’s 1366×768 panel. Resizing the virtual display fixed the horizontal scrolling. Installing a window manager alone wouldn’t have changed that geometry.

Running the services and reaching their manager are different problems

I split the components into user services so they could be supervised independently. The user manager already existed, and lingering was enabled, but systemctl --user from my SSH shell initially couldn’t contact it.

That shell lacked the runtime-directory and session-bus environment. The manager being alive didn’t fill in those variables for every process that might want to talk to it.

Once the SSH shell pointed at the existing user bus, I could manage the units. An early dependency failure also sent me back to the display service: failures above Xvfb could make several downstream units fail together.

After sorting out startup, the services were running and the remote GUI was usable. Chrome’s dedicated profile kept browser state separate from the lifetime of the noVNC connection.

SSH carries the connection, not the browser process

The laptop can maintain the tunnel without keeping a remote shell open. With a suitable SSH host entry, the connection has this shape:

ssh -fN -o ExitOnForwardFailure=yes \
    -L 6080:localhost:6080 lab-browser

lab-browser is a placeholder for the configured host. The viewer then connects to the local forwarded port. VNC and noVNC remain loopback listeners on the NUC.

I could close the viewer and leave Chrome running. Once an agent tried to use that browser, I had to check which Chrome instance it had connected to.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.