It can happen upon installing a fresh new distro that you have or haven’t used before, sometimes it may happen upon updating your current working-as-it-should distro…
In the end, it doesn’t matter ‘when’ or even ‘why’ exactly it happens (we’ll get to that in a moment), the important thing is – how can you fix it, right?
Fixing Invalid MIT-MAGIC-COOKIE-1
According to online resources it seems that the primary suggestion for solving this error has something to do with .Xauthority file that resides in Home folder.
Most of the resources you may encounter will advise you to simply delete the file in order for the problem to disappear.
This may work for ssh connections, however, it doesn’t seems to do the trick when it comes to the error popping up upon sudo.
So what does works?
Simply, open up sudoers file and edit a specific configuration in it like so:
remove the ‘#’ sign from the line where it says ‘ Defaults env_keep += “HOME” ‘ so you’ll end up having the configuration looking like the following image.
Of course, as the comment above it suggests, other programs may also use HOME to find configuration files and this may lead to privilege escalation!
So I wouldn’t advise you do so in case you have important, confidential files stored on your machine. Then again, If you do, you’d probably wouldn’t be reading this anyhow.
This one might be just little bit more tricky.
If you’re looking to enable sudo open up Xorg programs, yet, you prefer not to include the entire HOME folder as a viable authentication mechanism; you can simply edit the sudoers file like this: ‘ Defaults env_keep += “XAUTHORITY” ‘.
Nonetheless, the tricky part here is that you must have $XAUTHORITY variable defined on your distro as well, otherwise this will get you nowhere.
To do that for one session you may type the following in Terminal:
Or you can store the variable permanently in $HOME/.bashrc or more globally in /etc/environment, the choice is yours.