7

Tried to find some answer here: Can't launch graphical apps from terminal after updating to 15.10, but it didn't solve my problem.

$ sudo gedit
Failed 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:4574): Gtk-WARNING **: cannot open display:

only gedit in terminal works fine. This is my local computer, not a remote system.

Zanna
  • 70,465
  • 4
    Please copy and paste terminal outputs into your question. Images are annoying to read and aren't searchable. – TheWanderer Aug 28 '16 at 18:37
  • Did you try the first comment the question? – TheWanderer Aug 28 '16 at 18:38
  • http://askubuntu.com/questions/614387/gksu-gtk-warning-cannot-open-display-0 – TheWanderer Aug 28 '16 at 18:41
  • @Zacharee1 better? – Kaz Wolfe Aug 28 '16 at 18:45
  • For me, "sudo gedit" works awesome and I don't need gksudo, despite Zacharee1's insistence it is necessary. Please add more details. 1) from that terminal, can you run gui as your user, not as root? (what returns from gedit). 2) Is the terminal you are showing us on your LOCAL computer, or is it on a remote workstation? If you are on remote, then problem is certainly in your SSH forwarding of X11. Perhaps remote does not offer X11 forwarding, or you didnot ask for it. – pauljohn32 Aug 28 '16 at 19:09
  • @pauljohn32 only "gedit" in terminal works fine and this is my local computer not remote. – Inmate4587 Aug 28 '16 at 19:16
  • I would say that Mir is not yet ready for GUI apps that escalate privileges. This may be one of the reasons why making it default was recently delayed (again?). gksudo didn't work, because it is designed to work with X11, not Mir. Is there particular reason why you use Mir, or you don't care and are willing to switch back to X11? – Mirek Długosz Aug 28 '16 at 20:08
  • @miroslawZalewski I do not care about"mir" and "x11". I have fresh installed ubuntu 16.04.1 and I did nothing regarding these settings. I just want that "gksudo" or "sudo" with gui should work. – Inmate4587 Aug 29 '16 at 09:23
  • I'm not sure if this is related, but I had the same issue after renaming host after fresh install. I have followed that http://askubuntu.com/a/59517/373070 and rebooted; now both issues are gone. – Cieniek Nov 07 '16 at 11:37
  • Related, though probably not a duplicate, and with Wayland rather than Mir: Why don't gksu/gksudo work with Wayland? (As for sudo gedit, that command shouldn't be used, though the problem with it turns out not to have been related at all to the problem here. gksu gedit, gksudo gedit, kdesudo gedit, and as needed on systems that don't have gksu(do) or kdesudo , the now-common sudo -H gedit or sudo -i gedit, are all reasonably safe, but sudo gedit isn't. @pauljohn32) – Eliah Kagan Oct 04 '17 at 15:13

1 Answers1

17

Older post is below, but is still 100% valid.

Mir is not what one would consider stable/ready for operation. Most of the Ubuntu core (such as the below mentioned gksudo and other programs) still relies on X, and can't handle what Mir uses. Until further notice, it's recommended you switch back to X11 unless you have a very good reason to use Mir. If the latter is true, get comfy with sudo nano.


Repeat after me:

NEVER RUN GRAPHICAL PROGRAMS WITH sudo! *

*except in extremely rare cases where you know exactly what you're doing.... Or you have a thing for pain. Either/or.

Again. And once more to your dog for good measure.

Instead, use the gksudo command to launch a graphical command with root powers, like so:

gksudo gedit /var/log/auth.log

If your system does not have GKsudo installed on it, install it first with apt:

sudo apt install gksudo

Note that if you're running KDE, use the equivalent kdesudo command.


The reasoning behind this is that sudo does not preserve user-land permissions, which are very often used by graphical applications. For example, if you change the gedit config file after opening it with sudo, you'll have an issue where gedit's config file is now owned by root and is unreadable and/or unwriteable to you, the user.

gksudo takes care of this for you and handles all of the heavy lifting of ensuring that permissions stay the same and don't break anything.

Console commands are different because they often don't save userland configs, and are designed for the use of sudo as opposed to gksudo.

Kaz Wolfe
  • 34,122
  • 21
  • 114
  • 172
  • 1
    The question they link says gksudo doesn't work. I wonder if it works for OP... – TheWanderer Aug 28 '16 at 18:41
  • @Zacharee1 I'm not sure either, but it's still good advice that the OP should really be aware of. – Kaz Wolfe Aug 28 '16 at 18:43
  • well yeah it is :p – TheWanderer Aug 28 '16 at 18:44
  • Thanks for your whole description about "sudo" and "gksudo" but I am getting error after using "gksudo" too..like this

    gksudo gedit

    (gksudo:5648): GConf-CRITICAL **: gconf_value_free: assertion 'value != NULL' failed Unable to init server: Could not connect: Connection refused

    (gedit:5656): Gtk-WARNING **: cannot open display:

    – Inmate4587 Aug 28 '16 at 18:52
  • @Akhileshkumar Try rebooting. I think some environment variables got messed up and need to be reset. Display variables should never be null, even with Mir. – Kaz Wolfe Aug 28 '16 at 18:54
  • 1
    Couldn't have said it better myself :) – You'reAGitForNotUsingGit Aug 28 '16 at 18:55
  • @KazWolfe rebooting didn't worked..Is it possible that it is because of "BURG" I installed recently or A squid server I made to reduce the hassle of using proxy authentication again and again. – Inmate4587 Aug 28 '16 at 19:05
  • Akhilesh 's comment just now makes me think problem is that the ssh connection to the remote server did not include X11 forwarding. Probably little/nothing to do with sudo versus gksudo, more likely X11 forwarding. – pauljohn32 Aug 28 '16 at 19:11
  • @Akhileshkumar Neither of those would cause this. – Kaz Wolfe Aug 28 '16 at 19:20
  • @pauljohn32, you'd be surprised at gksudo vs sudo on this one. Do we know for a fact he's using X11 forwarding? – Kaz Wolfe Aug 28 '16 at 19:20
  • @KazWolfe: Question contains the [tag:mir] tag, so I don't even think (s)he is using X11. – Kevin Aug 29 '16 at 01:33
  • I heard we liked pkexec more than gksudo? is that true? – cat Aug 29 '16 at 03:58
  • 1
    @cat They do roughly the same thing. pkexec is considered more proper, but old habits die hard. – Kaz Wolfe Aug 29 '16 at 04:00
  • "cannot open display" sounds very much like an X-related error message :) What happens when a "DISPLAY=:0" is prepended to the privileged command? – rackandboneman Aug 29 '16 at 09:00
  • @KazWolfe I had just freshly installed Ubuntu 16.04.1 and did not touched anything related to "X11" or "MIR". Since you are referring that installing "X11" could solve my problem. Please Guide me to do that. – Inmate4587 Aug 29 '16 at 09:16