Copying X11 Magic Cookies
I rarely use GUIs, but when I do, it’s from CLI and every time I run into the annoying MIT-MAGIC-COOKIE-1 data did not match
error. It’s easy to fix, but it happens to me so rarely that between the fixes I forget how I did it.
So here’s a bash one-liner – sort of – to be ran after you sudo
to whatever other user account. This works best for the root
account as it relies on the target user to have passwordless sudo
access to the source user’s .Xauthority
file.
xauth add $(sudo xauth -f $(grep ^$(logname): /etc/passwd | awk -F: '{print $6}')/.Xauthority list | grep ":$(grep -oP "(?<=:)[0-9]{1,}(?=\.)" <<<${DISPLAY})\s")
You can add it as a convenient alias in your .bashrc
if this is something you plan on running often.