Mountain Lion ssh -X problems

Solution 1:

You need to open XQuartz, go to X11PreferencesSecurity, there are two check boxes: disable the first, enable the second. Restart XQuartz and try again. You will also need to define the $DISPLAY variable like this:

export DISPLAY=clienthost:0.0

Solution 2:

Not sure how this could happen, but from the SSH source where the error message comes:

/* Try to open a socket for the local X server. */
display = getenv("DISPLAY");
if (!display) {
    error("DISPLAY not set.");
    return -1;
}

It indicates that indeed ssh thinks the variable is not set at all (i.e. not malformed or something, but missing).

I'm not sure if SSH does change the user context so it gets a different environment. You can try

ssh -vvv ....

(multiple "v") to get more debug output, maybe this gives a hint somewhere in startup.