"Invalid MIT-MAGIC-COOKIE-1 key" message while running a program with the Terminal

I have a problem when running a certain program. The execution works perfectly fine, but there is an additional line that appears before the execution : Invalid MIT-MAGIC-COOKIE-1 key

Is there a way to prevent this message to appear ? With some research, I tried different commands :

  • Try xhost +local: before running

  • Change the variable DISPLAY with the export command

  • Check if the XAUTHORITY environment exists (it does not)

Do you have any other suggestions that I can try ?


Solution 1:

This indicates a permission Problem or simply a wrong magic cookie ..

  • what works for me: xhost + 192.168.1.2 for virtual boxes , then in the virtual machine : DISPLAY=192.168.1.1:0.0 dbus-run my-x11-program

  • the MIT-MAGIC-COOKIE is stored in the file .Xauthority of the user who is running the desktop

  • you might have an already wrong-filled .Xauthority ?

  • you could also just "steal" this one (transfer via ssh) or copy on localhost , sometimes sudo works , and su not

  • when everything fails: run via ssh with e.g ssh -YXC myuser@the-machine "the-command"

  • if you encounter failures concerning MPI_init() from openMPI, you should read the mpirun-gui section from the manual there is another thread in the SE community describing what MPI_Init() it does