One thing that troubled me moving to Ubuntu 9.10 Karmic Koala: my remote X applications stopped working with the error
X11 connection rejected because of wrong authentication
The reason seems to be that Gnome moved the location of X authorization to [wherever-the-hell-i-dont-remember], whereas ssh and everything else still use the same location (~/.Xauthority). Note: I clearly forgot whatever it was I discovered about xauth, so please enlighten me in the comments, and I will update this exceedingly lame paragraph.
This is going to be tagged as an Emacs post because my principal reason to use remote X is Emacs’ awesome make-frame-on-display command.
The bash script I use is saved in ~/bin/xauthmagic:
1 2 | #!/bin/bash xauth -f ~/.Xauthority list | grep -v ':0' | while read foo; do xauth add $foo; done |
This means: look through all the xauth cookies in ~/.Xauthority, remove the ‘:0′ (local) display cookie, take the remaining cookies and run the xauth command on them.
The steps I take to use this:
- On my remote host (emunah), start an ssh section forwarding X:
greg@emunah$ ssh greg@maui -Y
-
On my local host (maui), run the
xauthmagicscript abovegreg@maui$ ~/bin/xauthmagic
-
From my local host emacs, run
M-x make-frame-on-display RET localhost:10.0 RET
Et voilá!

2 Comments
Greg, I have this same problem, too. Is this xauth stuff really the “official” solution? I unfortunately know nothing about xauth.
I can ssh to my remote box with X forwarding and run “xeyes” just fine, and even emacs runs fine. My only problem is when I run emacsclient and try to create a new frame, I get the same error as you… I will try your solution! Thank you!
P.S. Everything did work fine until the upgrade to karmic…
@erikr, I have logged on to several Linux machines to determine their default Xauthority database location, using xauth -v. On Debian machines, I always get ~/.Xauthority. I get that result even on a server that has been upgraded to Karmic, but which does not have Gnome. On my laptop, however, I get /var/run/gdm/auth-for-gregj-3sy6gB/database. That path changes every time I log in, with different salt. Since everything else looks to your home .Xauthority file, this causes your emacsclient session to fail to authenticate.
I might try messing around with setting the XAUTHORITY environment variable, but I’m not sure that would work for Gnome.