xauth on snow leopard x11 xquartz

Posted on 2010-06-27(Sun) in posts

Something's bothered me when running commands via ssh in my Snow Leopard Mac for a while now. I've been running XQuartz rather than the default X11.app for reasons I can't even remember now. This problem persists in both.

$ ssh -X remote xlogo
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Warning: No xauth data; using fake authentication data for X11 forwarding.

Turns out they can both be fixed if you have xauth set up right. Seems xauth doesn't like local DISPLAY names with periods in it.

$ xauth generate $DISPLAY .
xauth: (argv):1: bad display name "/tmp/launch-158PCz/org.macosforge.xquartz:0" in "add" command

$ echo $DISPLAY
/tmp/launch-158PCz/org.macosforge.xquartz:0

I read a few places online and most of them recommended ignoring the problem. lots said not to change the DISPLAY variable. I found one (I forget where) that fixed the problem using symlinks and here's my implementation of that. I added this to a path that gets executed from my .bashrc

if [ -e "$DISPLAY" ]; then
DISPDIR=$(dirname $DISPLAY)
NEWDISP="${DISPDIR}/:0"
if [ ! -e "$NEWDISP" ]; then
ln -s "$DISPLAY" "$NEWDISP"
xauth -q generate "$NEWDISP" .
fi
export DISPLAY="$NEWDISP"
fi

If any of this is a tremendously bad idea just let me know!

You might be tempted to add ForwardX11Trusted to you ~/.ssh/config but I've heard that's a bad idea.