from hyperfluid (snipped)
... is there a method to automate this procedure properly when logging in/starting X?
There are probably several ways, but here is how I did it after reading this thread through. I use KDE, so you may have to modify it for your desktop.
Create a file named "x4su.sh" in /home/youruser/.kde/Autostart. This file should contain the lines:
xauth extract /tmp/x4su $DISPLAY
Make the file executable.
Non-login consoles such as xterm/konsole programmatically source ~/.bashrc, so as root, add the line:
xauth merge /tmp/x4su
to the bottom of /root/.bashrc. Create the file if it doesn't exist.
Now when you log in to KDE, the display cookie will be exported to /tmp/x4su & when you open a terminal as root, that file will be merged with /root/.Xauthority.
This works for me, but, as stated, you may have to do some modifications, depending on DE used, etc.