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.

3
  • 2
    Try removing .Xauthority - sudo rm -f ~/.Xauthority and then restarting.
    – user423626
    May 6, 2016 at 14:00
  • Nah, same thing.
    – sssemil
    May 6, 2016 at 14:13
  • @user423626, thank you! I had this problem after a complete reinstallation and copying over the configuration files from the old system.
    – Esmu Igors
    Aug 2, 2021 at 14:01

6 Answers 6

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).

3
  • I've had problems where I can open GUI applications from the terminal as root, but not as a regular user. In that case, running xhost + as root allowed me to then start the GUI applications as a regular user.
    – Craig Otis
    Jul 18, 2019 at 16:25
  • This worked! Thanks! Apr 2, 2020 at 15:43
  • This works but has security implications. See the answer below about this.
    – Fmstrat
    Apr 28, 2021 at 1:43
15

Odd but export DISPLAY=:1 helped. Cheers.

6
  • 5
    Are you running multiple X displays or something? Default should be :0
    – user423626
    May 6, 2016 at 14:17
  • 3
    exactly the same issue (on 16.04 in my case); unfortunately this doesn't work.
    – adam.smith
    May 7, 2016 at 11:45
  • 1
    Nope, only one. ":0" was always default but something changed after update.
    – sssemil
    May 7, 2016 at 17:01
  • 2
    In my case, setting DISPLAY to :0 solved it (while :1 did not)
    – mbello
    Jan 27, 2017 at 12:54
  • 1
    In my case, setting DISPLAY to :2 solved it. Just have to keep trying,.
    – zkytony
    Dec 30, 2018 at 20:25
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:
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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .