Can’t Start GUI Programs via Command Line – Wrong DISPLAY Variable

command linedisplay-managerxorg

I am using Ubuntu 18.10 and I cannot launch GUI programs via the command line. This applies to subl (for Sublime Text) and Firefox. When trying to start Firefox via CLI; it prints: Invalid MIT-MAGIC-COOKIE-1 key.

My environment shows:

➜ echo $DISPLAY
:0.0

And I do have a file with that cookie:

➜ echo $XAUTHORITY 
/run/user/1000/gdm/Xauthority
➜ cat /run/user/1000/gdm/Xauthority
voltaireMIT-MAGIC-COOKIE-1OZ��8�ص������v�voltaireMIT-MAGIC-COOKIE-1OZ��8�ص������v%    

Also:

➜ xauth list
voltaire/unix:  MIT-MAGIC-COOKIE-1  4f5abfd438eb88d8b586f0fbad8aee76
#ffff#766f6c7461697265#:  MIT-MAGIC-COOKIE-1  4f5abfd438eb88d8b586f0fbad8aee76

It seems that two Xorg processes are running:

➜ ps aux | grep xorg
root      1400  0.0  0.1 213748 48068 tty1     Sl+  09:29   0:00 /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/121/gdm/Xauthority -background none -noreset -keeptty -verbose 7 -core
root      4701  1.9  0.5 658612 195732 tty2    Sl+  09:30   1:50 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 7 -core

I previously had lightdm installed to fix a login issue, and I have the current NVIDIA graphics drivers installed on my system. I guess this is very much related?

When I run:

DISPLAY=:1 subl

it works!

What could I do to fix this?


Update

I deleted ~/.Xauthority and rebooted, but the problem still remains.

Best Answer

The issue was that DISPLAY was incorrectly set to :0.0 by a shell configuration file. Once I removed that, launching programs from the shell was possible again.

You can use this command to search through all the default shell configuration files:

grep "DISPLAY" ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login \
               ~/.bash_aliases /etc/bash.bashrc /etc/profile \
               /etc/profile.d/* /etc/environment 2> /dev/null

There are indeed two Xorg processes, which is expected behavior, so this should not be an issue in itself.

Also, the .Xauthority file does not seem to be necessary.