5

I've run into a problem in that if I start Emacs in daemon mode on my remote system, then in my local system I run ssh remotehost emacsclient -c, it fails with X11 connection rejected because of wrong authentication. However, things like ssh remotehost xterm work fine, so it's nothing to do with ssh connections, X forwarding, etc.

Both systems in question are running Ubuntu 18.04 LTS.

The problem, as could be guessed, is xauth and in particular after much reading of issues filed back in 2010/2011, it seems to be due to the way GDM sets the XAUTHORITY environment variable to $XDG_RUNTIME_DIR/gdm/Xauthority (something like /run/user/1000/gdm/Xauthority), while incoming SSH connections do not set XAUTHORITY before the set up xauth cookies for the SSH session.

This means that ssh xauth cookies are added in the default $HOME/.Xauthority file. My Emacs daemon cannot see these cookies because it's using the GDM $XDG_RUNTIME_DIR/gdm/Xauthority file.

As I've said it seems like this disparity has been a known issue for 8+ years... has no one resolved it? Crazy. I have written a script that installs the cookie but having to do so is pretty gross.

Is there a way to get my ssh session to use the GDM Xauthority file? I've tried setting XAUTHORITY in my shell setup but apparently that is set too late, after the SSH daemon configures the new Xauth cookie, because it's still put into $HOME/.Xauthority.

2
  • This blog post seems to have answers: blog.allardhendriksen.nl/posts/remote-emacs-on-gnome-using-x
    – Jim Blandy
    Mar 10, 2022 at 17:46
  • I think it's going to be hard to get SSH to put its cookies in the right place, since it seems like modern GDM chooses a fresh path for each session's authority file. For example, mine is /run/user/1000/.mutter-Xwaylandauth.6WSOI1 at the moment. If there were multiple GDM sessions live at the same time, it wouldn't be clear which one SSH should use.
    – Jim Blandy
    Mar 10, 2022 at 17:50

1 Answer 1

0

It's indeed hard to guess where the X file is. In my case I ended up hacking some shell thing to do it as part of a wrapper around emacsclient. The relevant bits are:

fix_xauth() (
  if [[ -z "$XDG_RUNTIME_DIR" ]]; then return; fi
  if [[ ! -e "$HOME/.Xauthority" ]]; then return; fi
  shopt -s nullglob; shopt -u failglob
  for xauth in "$XDG_RUNTIME_DIR/"{".mutter-Xwaylandauth"*,"gdm/Xauthority"}; do
    if [[ ! -f "$xauth" ]]; then continue; fi
    xauth -f "$xauth" merge "$HOME/.Xauthority"
  done
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.