How do I run X11 applications remotely?

Solution 1:

Xpra (as mentioned here) does what I want. It allows running arbitrary X applications, which can be forwarded to multiple clients, either on the same computer, or on another machine. It supports running OpenGL apps, too, and allows your apps to continue running even after the last client disconnects — giving you the chance to reconnect later.

xpra comes in two parts: a client and a server. To start up the server, run the following on the remote machine:

$ xpra start :100

This starts up xpra on a new X display. (There's a workaround to use with a proxy.)

To have an application controlled by xpra, run it on the same display as the xpra server, like this:

$ export DISPLAY=:100
$ firefox&
$ blender&
...

This can all be done through an ssh connection (with or without X11-Forwarding) with no problems.

To start up a client, do one of the following:

$ ssh -X user@remotehost
<gain remote connection>
$ xpra attach :100

or

$ xpra attach ssh:user@remotehost:100

Note that the latter requires the xpra client to be installed on your local machine; the former does not.

The xpra client will put an icon in your window manager's task bar/panel allowing you to disconnect the client. (Or, you can just kill it, so long as you're careful not to kill the server.) You can then reattach later, as long as the xpra server is still running. If you have a single xpra server running on the host, you can also simply omit the display number, and xpra attach will figure it out.

One very nice feature of xpra is that it allows you to start a server on a pre-existing display. This allows you to recover a session if the xpra server crashes (as long as the X server on that display is still running). To do this, run

$ xpra start --use-display :100

Caveats:

  • xpra runs as a window manager. Although it plays pretty nicely with embedding in other window managers, it doesn't play so well with the X apps themselves: It doesn't allow, e.g. rxvt-unicode to remove its title bar; also it doesn't tell windows how much space they have to work with on-screen, e.g., drop-down boxes and menus fall off-screen. I think the latter problem is a matter of fixing my configuration, however.

  • Keys get repeated. Frequently. This can be solved by using xpra attach --no-keyboard-sync, but the man page warns that this doesn't work well with certain games. I'm keeping my fingers crossed that I don't find myself yearning to use one of these games.

For these reasons, Xephyr may well be a better solution (once it supports GLX), because it runs as an X server, not a window manager. I haven't investigated whether it supports resuming previously disconnected sessions, however.