Here are two of the biggest problems I’ve come across in using X11 with SSH connections, and how to get around them.
OS X employs a combination of the X.org package and Xquartz, a component included in Mac’s X (or X11) to help it run on OS X. Getting these two to work in concert once one of them, or the operating system itself, has been upgraded can be frustrating.
It used to be the case that in order to get X working remotely from an OS X machine, you needed to set your DISPLAY system variable to something that made sense to non-Mac systems (such as “localhost:0“). But if you’re running the latest version of Leopard (10.5.3), X11 (2.2.1), and Xquartz (1.3.0), doing so is not only unnecessary, but it can keep your X sessions from launching properly. If you’re seeing errors like this on your side when launching an X application:
Error: Can't open display: localhost:0
… or like this on a remote host:
connect localhost port 6000: Connection refused
… it’s probably the case that you need to un-set your DISPLAY variable. Try removing any commands that export a DISPLAY value to your environment (such as ‘export DISPLAY=something‘), logging out of your current sessions, and see if you can successfully launch your X app. You’ll also need to not launch X11 explicitly: let the OS launch it for you on its own when you request an X application (test by running xterm or xclock from a terminal).
Inversely, in the version of X native to OS X 10.5.2, you may see a wacky-looking error like the following when launching an X application on a remote host:
/tmp/launch-rkTZqq/: unknown host. (nodename nor servname provided, or not known) X connection to localhost:39.0 broken (explicit kill or server shutdown).
If you check your local DISPLAY variable (with echo $DISPLAY), you may see an equally strange value:
echo $DISPLAY /tmp/launch-rkTZqq/
Essentially, you need to do the exact inverse of the above fix: explicitly set the value of DISPLAY in your environment before launching an X app on a remote host:
You can do this as a command, or by adding this line to a profile (such as ~/.bash_profile) so that it gets read automatically at the start of each session. In addition, you may need to explicitly launch X11 (Applications -> Utilities -> X11, or search Spotlight for “X11″) before launching an X application.
Why two successive versions of the same software require such polar fixes is beyond me! But at least now you may know how to deal with the problem in your particular environment.
If you need additional help or troubleshooting information, sao1’s Leopard and X11 blog is a great resource.