17

After updating to 15.10 it's impossible to run graphical apps from terminal:

xxx@xxx:~$ gksudo wireshark
Invalid MIT-MAGIC-COOKIE-1 key
(gksudo:5532): Gtk-WARNING **: cannot open display: :0
xxx@xxx:~$ sudo -H wireshark
[sudo] password for xxx: 
Invalid MIT-MAGIC-COOKIE-1 key
** (wireshark:5535): WARNING **: Could not open X display
Invalid MIT-MAGIC-COOKIE-1 keyFailed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(wireshark:5535): Gtk-WARNING **: cannot open display: :0
xxx@xxx:~$ wireshark
Invalid MIT-MAGIC-COOKIE-1 key
** (wireshark:5569): WARNING **: Could not open X display
Invalid MIT-MAGIC-COOKIE-1 keyFailed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(wireshark:5569): Gtk-WARNING **: cannot open display: :0
xxx@xxx:~$ gedit
Invalid MIT-MAGIC-COOKIE-1 key
** (gedit:5570): WARNING **: Could not open X display
Invalid MIT-MAGIC-COOKIE-1 keyFailed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(gedit:5570): Gtk-WARNING **: cannot open display: :0
xxx@xxx:~$ sudo gedit
Invalid MIT-MAGIC-COOKIE-1 key
** (gedit:5574): WARNING **: Could not open X display
Invalid MIT-MAGIC-COOKIE-1 keyFailed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused

(gedit:5574): Gtk-WARNING **: cannot open display: :0

My little research pointed to gksudo using but it ain't working either. I've also tried some stuff with xauth. What is the problem? Thanks.

sssemil
  • 471
  • 1
  • 4
  • 13

6 Answers6

24

As a regular user, run the command xhost +. After that, try running your graphical application again.

This turns off host-based access control on the X server. Here is the relevant information from the man page:

The xhost program is used to add and delete host names or user names to the list allowed to make connections to the X server.

+ Access is granted to everyone, even if they aren't on the list (i.e., access control is turned off).

jncraton
  • 173
  • 1
  • 7
jet
  • 7,274
15

Odd but export DISPLAY=:1 helped. Cheers.

sssemil
  • 471
  • 1
  • 4
  • 13
  • 5
    Are you running multiple X displays or something? Default should be :0 –  May 06 '16 at 14:17
  • 3
    exactly the same issue (on 16.04 in my case); unfortunately this doesn't work. – adam.smith May 07 '16 at 11:45
  • 1
    Nope, only one. ":0" was always default but something changed after update. – sssemil May 07 '16 at 17:01
  • 2
    In my case, setting DISPLAY to :0 solved it (while :1 did not) – mbello Jan 27 '17 at 12:54
  • 1
    In my case, setting DISPLAY to :2 solved it. Just have to keep trying,. – zkytony Dec 30 '18 at 20:25
  • export DISPLAY=:1 worked for me. I've had this problem (Ubuntu 20.04) since I installed nvidia-utils-440 and nvidia-driver-440. Another site mentioned the who command, which for me does include :1 twice. – user643722 Aug 25 '20 at 11:27
3

Warning: Improper use of xhost can inadvertently give every host on the Internet full access to an X display server.

Generally you shouldn't turn off host-based access control on the X server unless you know what you're doing. Instead you should only allow the things that require access.

Solution:

Execute: xhost +si:localhost:root

The above solution also works for Wayland users executing an elevated XWayland application.

When attempting to run an XWayland application with elevated permissions you may receive the following error:

No protocol specified
Unable to init server: Could not connect: Connection refused
Could not parse arguments: Cannot open display:
Loligans
  • 131
  • 2
1

In my case, the same problem found after updating a single package gnome-shell through synaptic-package-manager. Immediately after next login I was not able to access any GUI part of the OS. Did lots of searching, finaly,

when I used apt install gdm3 from recovery mode terminal, I was able to find a login prompt after system boot(Only terminal, not GUI).

After that I tried apt install gnome which installed a whole bunch of components along, once downloads finished, I was able to get my OS in GUI mode.

If you're not getting login prompt itself then try to follow above step in recovery mode. Otherwise try installing Gnome which updates the gdm3 along.

1
export DISPLAY=:0

This is what worked for me on 20.04

-3

This worked on Ubuntu 20.10 with gnome 40.4.0

Instead of opening the terminal and typing the command: gparted and being prompted to input password for root (which ended up giving me the error), I simply typed: sudo gparted and entered the password in the terminal, [rather than the graphical prompt].

I tried everything listed above and nothing worked, and I said well let me just use sudo to begin with...

And it worked.

ThunderBird
  • 1,955
  • It's not so great because using sudo to launch graphical applications is not recommended. – karel Nov 30 '21 at 04:50