How to run X11 applications remotely

x11-forwardingxephyrxorg

How can I run X11 applications hosted on a remote server, given the following goals:

  • Run anything that would run locally on the server. This includes OpenGL apps which use GLX.
  • Seemless integration with local desktop, i.e., the apps look like they're running locally, without a separate desktop area. Thus, I need an X11 solution, not a wrapper protocol.
  • Preferably allows the applications to continue running if I get disconnected; then, I can reopen the running apps later when I reconnect.

I've seen a lot of advice floating about here on superuser, but much of it is
a partial fix or just plain bad.

  • plain ssh X11-Forwarding is out: It can't run certain apps, especially those relying on the GLX extension.
  • Setting LIBGL_ALWAYS_INDIRECT=1 does not work for me.
  • Xephyr is also out. It doesn't currently support GLX, although I've seen some GLX work in the development tree. Perhaps in the future, that will be the cleanest way.
  • xmove is also out. It's too old to consider further.
  • VNC is out. It forwards the whole desktop, and can't grok the X protocol.

EDIT: I fought over a weekend to make several suggestions work out, and xpra is what works best. I've described my setup in an answer below, and I hope it helps someone else.

Best Answer

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.

Related Question