I'm trying to set up xauth cookie forwarding between users, so that GUI programs could be run as any user via SSH. I have added the following line to /etc/pam.d/su and /etc/pam.d/sudo:

session    optional   pam_xauth.so

However, running GUI programs as root still fails:

pi@raspberrypi:~ $ echo $DISPLAY
pi@raspberrypi:~ $ xauth list
raspberrypi/unix:12  MIT-MAGIC-COOKIE-1  XXX
raspberrypi/unix:11  MIT-MAGIC-COOKIE-1  XXX
raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  XXX
raspberrypi/unix:10  MIT-MAGIC-COOKIE-1  XXX
pi@raspberrypi:~ $ leafpad
# leafpad window opens

pi@raspberrypi:~ $ sudo su
root@raspberrypi:/home/pi# echo $DISPLAY
root@raspberrypi:/home/pi# xauth list
xauth:  file /root/.Xauthority does not exist
root@raspberrypi:/home/pi# leafpad
PuTTY X11 proxy: Unsupported authorisation protocol
leafpad: Cannot open display:

root@raspberrypi:/home/pi# touch /root/.Xauthority
root@raspberrypi:/home/pi# xauth add $(xauth -f ~pi/.Xauthority list | tail -1)
root@raspberrypi:/home/pi# leafpad
# leafpad window opens

I don't have any ~/.xauth/import/~/.xauth/export files for any of the users. I'm running PuTTY+Xming on the SSH client side (not that it should matter). I was expecting pam_xauth to create /root/.Xauthority for me, but that didn't happen. Any idea why?

  • And if you replace sudo su with sudo -i ? – Jiri B Mar 7 at 8:51
  • @JiriB I get exactly the same error message. – Dmitry Grigoryev Mar 8 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.