Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Featured

Copying X11 Magic Cookies

Submitted by on August 10, 2018 – 4:17 pm

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.

Print Friendly, PDF & Email

Leave a Reply