You are not logged in.

#1 2016-10-29 12:12:03

dtyj
Member
Registered: 2016-10-29
Posts: 5

Gtk-WARNING **: cannot open display: :0.

I think few days ago when I'm installing something, I might have screwed up some of my settings which now does not allow me to run certain stuffs.
Here is the problem below:

[dtyj@archlinux ~]$ sudo gedit
[sudo] password for root:
Unable to init server: Could not connect: Connection refused

(gedit:12380): Gtk-WARNING **: cannot open display: :0.
The above does not allow me to open gedit.
I've tried some solution like xhost and it still doesn't work, perhaps someone can shed some light on this?

Thanks!

Last edited by dtyj (2016-10-29 12:52:21)

Offline

#2 2016-10-29 12:16:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: Gtk-WARNING **: cannot open display: :0.

Have you tried gnome on xorg?

As of a recent update, gnome defaults to using wayland instead of xorg.  The laundry list of breakage this has caused seems immeasurable.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2016-10-29 12:54:08

dtyj
Member
Registered: 2016-10-29
Posts: 5

Re: Gtk-WARNING **: cannot open display: :0.

Trilby wrote:

Have you tried gnome on xorg?

As of a recent update, gnome defaults to using wayland instead of xorg.  The laundry list of breakage this has caused seems immeasurable.

Hmm, not idea what you meant. I'm still pretty much new to this Arch Linux thing hmm
Here's a screenshot if that helps, http://imgur.com/a/kt2k1

Last edited by dtyj (2016-10-29 13:07:19)

Offline

#4 2016-10-29 12:55:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: Gtk-WARNING **: cannot open display: :0.

It's fine to not know what I meant.  It's less fine to not have bothered to follow the link I provided which would help you learn and know exactly what I meant.  The screenshot really doesn't help.  You did a good job of describing the problem in the first post - the cause of the problem is almost certainly related to gnome running on wayland.  I gave you the means to test that possibility. Please do so.

EDIT: actually, on second look maybe this isn't a wayland issue if it only happens when using sudo: you should not run gui programs (especially gtk ones) with sudo, use gksu.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2016-10-29 13:32:30

dtyj
Member
Registered: 2016-10-29
Posts: 5

Re: Gtk-WARNING **: cannot open display: :0.

Trilby wrote:

It's fine to not know what I meant.  It's less fine to not have bothered to follow the link I provided which would help you learn and know exactly what I meant.  The screenshot really doesn't help.  You did a good job of describing the problem in the first post - the cause of the problem is almost certainly related to gnome running on wayland.  I gave you the means to test that possibility. Please do so.

EDIT: actually, on second look maybe this isn't a wayland issue if it only happens when using sudo: you should not run gui programs (especially gtk ones) with sudo, use gksu.

Okay here's what I have done so far.

I've created a new file at ~/.xinitrc with the following content: exec gnome-session
and I ran startx after that and it gave me this error:

[dtyj@archlinux ~]$ startx
xauth:  file /home/dtyj/.Xauthority does not exist
xauth:  file /home/dtyj/.Xauthority does not exist

/usr/lib/xorg-server/Xorg.wrap: Only console users are allowed to run the X server

^Cxinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: unexpected signal 2
Couldn't get a file descriptor referring to the console
---
Note: My current setup was using Xorg.

Thank you!

Offline

#6 2016-10-29 15:11:33

kourosh.daryaee
Member
Registered: 2016-10-29
Posts: 2

Re: Gtk-WARNING **: cannot open display: :0.

Hello there , I have similar problem, I just installed Arch Linux and gnome on Xorg ,now my problem is i want to use gedit with root privileges
when I open gedit as a normal user there's no problem but when I use it as root or with sudo or gksu (i dont know what gksu just read somewhere it might be useful)
i get the following error :

Unable to init server: Could not connect: Connection refused

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

Thank you.

Last edited by kourosh.daryaee (2016-10-29 15:12:43)

Offline

#7 2016-10-29 15:17:41

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: Gtk-WARNING **: cannot open display: :0.

Because gnome session will default to wayland. Doesn't work on Xorg for obvious reasons.

Have you ever (notably when writing the OP) managed to boot into a graphical session?
For a beginner, it's better to use a DM (GDM, if you prefer gnome) to achieve that. (See the install guide on the wiki)

Starting a GUI process from a VT (thing that looks like DOS) won't work (easily and certainly not if there's no running display server), so ensure to log into a graphical session first. The report on remaining problems.

Offline

#8 2016-10-29 16:16:18

kourosh.daryaee
Member
Registered: 2016-10-29
Posts: 2

Re: Gtk-WARNING **: cannot open display: :0.

Thank you. installed GDM and changed DISPLAY environment to :1 and it worked.

export DISPLAY=:1

Offline

#9 2016-10-29 19:14:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,529
Website

Re: Gtk-WARNING **: cannot open display: :0.

dtyj wrote:

Okay here's what I have done so far.

I've created a new file at ~/.xinitrc with the following content: exec gnome-session
and I ran startx after that and it gave me this error:

[dtyj@archlinux ~]$ startx

I don't know where you got this idea - you can't startx from within gnome.  I linked to the gnome article about running gnome under X (not trying to start X under gnome).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2016-10-30 02:40:43

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: Gtk-WARNING **: cannot open display: :0.

I too am facing the same issue as OP:

$ sudo nautilus
 
No protocol specified
Unable to init server: Could not connect: Connection refused
(nautilus:1627): Gtk-WARNING **: cannot open display: :0

I cannot open any gui, like gedit, nautilus etc using SUDO. However, I can if I SU.
(I have always used 'sudo'. Mine is a two/three year old Arch-gnome install, with GDM).

I suspect some SUDO issue with X-applications.. Will look further into the issue later, meanwhile any help is welcome.
(For now, lets say, 'gksu' is not an option)

Regards


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#11 2016-10-30 04:56:03

dtyj
Member
Registered: 2016-10-29
Posts: 5

Re: Gtk-WARNING **: cannot open display: :0.

Trilby wrote:
dtyj wrote:

Okay here's what I have done so far.

I've created a new file at ~/.xinitrc with the following content: exec gnome-session
and I ran startx after that and it gave me this error:

[dtyj@archlinux ~]$ startx

I don't know where you got this idea - you can't startx from within gnome.  I linked to the gnome article about running gnome under X (not trying to start X under gnome).

Well I'm sorry if I'd misinterpreted the instructions (After editing the ~/.xinitrc file, GNOME can be launched with the startx command ). The stuff that I'd tried it's still not working, running under gksu (also shows the same error, "Gtk-Warning **: cannot open display : :0."), and after rebooting still shows the same error).

Offline

#12 2016-10-30 06:43:22

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: Gtk-WARNING **: cannot open display: :0.

fantab wrote:

I too am facing the same issue as OP

Do you log into gnome on wayland (which is now the default) or gnome on X11?

Either way, a naive "sudo" will not work with most GUI processes, you'll *at least* have to preserve the environment

sudo -E nautilus

This however is a security problem, that's why the GUI elevations exist (they preserve only the relevant stuff and do some more)

On top of this, there should be no reason at all to run nautilus as root.

Offline

#13 2016-10-30 06:45:24

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: Gtk-WARNING **: cannot open display: :0.

dtyj wrote:

The stuff that I'd tried it's still not working, running under gksu (also shows the same error, "Gtk-Warning **: cannot open display : :0."), and after rebooting still shows the same error).

You've still not said whether this is on wayland. If you log into gnome and didn't explicitly choose "gnome on xorg" on login, the answer is "yes" and you can expect this and more trouble.

Offline

#14 2016-10-30 07:54:32

dtyj
Member
Registered: 2016-10-29
Posts: 5

Re: Gtk-WARNING **: cannot open display: :0.

seth wrote:
dtyj wrote:

The stuff that I'd tried it's still not working, running under gksu (also shows the same error, "Gtk-Warning **: cannot open display : :0."), and after rebooting still shows the same error).

You've still not said whether this is on wayland. If you log into gnome and didn't explicitly choose "gnome on xorg" on login, the answer is "yes" and you can expect this and more trouble.

It was logged into as gnome,and I've tried as gnome on xorg but the problem still persist.

Offline

#15 2016-10-30 08:03:15

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Gtk-WARNING **: cannot open display: :0.

it isn't just a security problem, it's also known to cause permission problems, changing ownership of certain user files to root, preventing running a graphical session without chowning the user's home folder to them.
the first thing I would try, knowing that the user consistently runs gui apps using sudo is to chown the user's files back to them

sudo chown $USER:$GROUPS $HOME

Offline

#16 2016-10-30 08:25:26

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: Gtk-WARNING **: cannot open display: :0.

seth wrote:
fantab wrote:

I too am facing the same issue as OP

Do you log into gnome on wayland (which is now the default) or gnome on X11?

Either way, a naive "sudo" will not work with most GUI processes, you'll *at least* have to preserve the environment

sudo -E nautilus

This however is a security problem, that's why the GUI elevations exist (they preserve only the relevant stuff and do some more)

On top of this, there should be no reason at all to run nautilus as root.

Thanks seth.

I use default, wayland.
'sudo' worked fine until a couple of days back (and its been working since I've been using linux). its only since yesterday that I have come across this issue.

sudo -E works.

I mostly use gedit as root, but I do rarely use Nautilus too as root. I find it simpler when editing multiple files as root.

regards..


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#17 2016-10-30 11:58:45

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: Gtk-WARNING **: cannot open display: :0.

dtyj wrote:

It was logged into as gnome,and I've tried as gnome on xorg but the problem still persist.

OK, stay for gnome on xorg for the moment and post the *exact* command(s) you tried to execute.
And please confirm that this is only a problem with priv elevation, ie. if you try to execute something as root.
Also mind my other comment itr, you should not and not have to run graphical processes as root. Bad idea.

Offline

#18 2017-05-22 08:08:24

varun
Member
Registered: 2014-07-14
Posts: 25

Re: Gtk-WARNING **: cannot open display: :0.

sudo -E worked for nautilus but was not working for gparted

running xhost +local: fixed all things for me for current session.

Offline

#19 2017-05-22 08:46:56

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Gtk-WARNING **: cannot open display: :0.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB