Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"E233: cannot open display" when starting gvim on ubuntu 8.04 root shell

12,944 views
Skip to first unread message

TsanChung

unread,
Aug 30, 2009, 4:52:39 PM8/30/09
to
"sudo gvim" is ok on a non-root shell.
$ sudo gvim /etc/fstab
[sudo] password for ts:

However, "E233: cannot open display" error appears when starting gvim
on ubuntu 8.04 root shell.
# gvim /etc/fstab
E233: cannot open display
Press ENTER or type command to continue
# kdesudo gvim /etc/fstab
kdesudo: cannot connect to X server

Nico Kadel-Garcia

unread,
Aug 30, 2009, 5:02:22 PM8/30/09
to

What does 'DISPLAY' say, before and after you run the sudo?

# echo $DISPLAY
# sudo echo $DISPLAY

Andrew Halliwell

unread,
Aug 30, 2009, 5:11:19 PM8/30/09
to

That's now X works.
To use X from another user, such as root, the DISPLAY environment variable
must be set and the X server TOLD to allow it.

Try this...
xhost + localhost
sudo DISPLAY=localhost:0.0
sudo gvim

--
| spi...@freenet.co,uk | "Are you pondering what I'm pondering Pinky?" |
| Andrew Halliwell BSc | |
| in | "I think so brain, but this time, you control |
| Computer Science | the Encounter suit, and I'll do the voice..." |

Nico Kadel-Garcia

unread,
Aug 30, 2009, 5:22:52 PM8/30/09
to
On Aug 30, 5:11 pm, Andrew Halliwell <spi...@ponder.sky.com> wrote:

> TsanChung <tsanchung.w...@gmail.com> wrote:
> > "sudo gvim" is ok on a non-root shell.
> > $ sudo gvim /etc/fstab
> > [sudo] password for ts:
>
> > However, "E233: cannot open display" error appears when starting gvim
> > on ubuntu 8.04 root shell.
> > # gvim /etc/fstab
> > E233: cannot open display
> > Press ENTER or type command to continue
> > # kdesudo gvim /etc/fstab
> > kdesudo: cannot connect to X server
>
> That's now X works.
> To use X from another user, such as root, the DISPLAY environment variable
> must be set and the X server TOLD to allow it.
>
> Try this...
> xhost + localhost
> sudo DISPLAY=localhost:0.0
> sudo gvim

I strongly, strongly recommend against using xhost this way. xhost is
a very powerful, and very dangerous command, that can allow massive
access to unauthorized people to your X session, for stealing
keystrokes and windows with root access and other

I regularly use 'sudo command arguments' from an X session as a non-
root user, allowing root to pop open a window using the already
available 'DISPLAY' settings. I assume kdesudo does the same thing
properly?

Andrew Halliwell

unread,
Aug 30, 2009, 7:08:44 PM8/30/09
to
Nico Kadel-Garcia <nka...@gmail.com> wrote:
> I strongly, strongly recommend against using xhost this way. xhost is
> a very powerful, and very dangerous command, that can allow massive
> access to unauthorized people to your X session, for stealing
> keystrokes and windows with root access and other

If the machine is single user, such as mine, there's no harm in opening
xhost to localhost. But yes, if it's a shared machine with multiple users
and sessions, it's not THAT good an idea.



> I regularly use 'sudo command arguments' from an X session as a non-
> root user, allowing root to pop open a window using the already
> available 'DISPLAY' settings. I assume kdesudo does the same thing
> properly?

There's also sux on some distros (if you don't have kde installed).
--
| |What to do if you find yourself stuck in a crack|
| spi...@freenet.co.uk |in the ground beneath a giant boulder, which you|
| |can't move, with no hope of rescue. |
| Andrew Halliwell BSc |Consider how lucky you are that life has been |
| in |good to you so far... |
| Computer Science | -The BOOK, Hitch-hiker's guide to the galaxy.|

TsanChung

unread,
Oct 7, 2009, 5:40:36 PM10/7/09
to
On the root shell of Konsole on ubuntu 8.04.
# DISPLAY=localhost:0.0
# xclock
Error: Can't open display: localhost:0.0

# gvim /etc/fstab
E233: cannot open display
Press ENTER or type command to continue
# kdesudo gvim /etc/fstab
kdesudo: cannot connect to X server

# xhost + localhost
xhost: unable to open display "localhost:0.0"

# DISPLAY=:0.0
# xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0.0
# DISPLAY=:0
# xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0

On Aug 30, 5:11 pm, Andrew Halliwell <spi...@ponder.sky.com> wrote:

> TsanChung <tsanchung.w...@gmail.com> wrote:
> > "sudo gvim" is ok on a non-root shell.
> > $ sudo gvim /etc/fstab
> > [sudo] password for ts:
>

> > However, "E233:cannotopendisplay" error appears when starting gvim


> > on ubuntu 8.04 root shell.
> > # gvim /etc/fstab
> >E233:cannotopendisplay
> > Press ENTER or type command to continue
> > # kdesudo gvim /etc/fstab

> > kdesudo:cannotconnect to X server


>
> That's now X works.

> To use X from another user, such as root, theDISPLAYenvironment variable


> must be set and the X server TOLD to allow it.
>
> Try this...
> xhost + localhost

> sudoDISPLAY=localhost:0.0

Allen Kistler

unread,
Oct 7, 2009, 7:51:56 PM10/7/09
to
TsanChung wrote:
> On the root shell of Konsole on ubuntu 8.04.
> # DISPLAY=localhost:0.0
> # xclock
> Error: Can't open display: localhost:0.0
> # gvim /etc/fstab
> E233: cannot open display
> Press ENTER or type command to continue
> # kdesudo gvim /etc/fstab
> kdesudo: cannot connect to X server
>
> # xhost + localhost
> xhost: unable to open display "localhost:0.0"
>
> # DISPLAY=:0.0
> # xclock
> Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0.0
> # DISPLAY=:0
> # xclock
> Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0

You'll get that error if /etc/hosts defines only 127.0.0.1 as localhost,
but you're connected over IPv6. Edit /etc/hosts so that BOTH 127.0.0.1
and ::1 are defined as localhost.

Since you're apparently connected via ssh, you really shouldn't have to
mess with xhost. In fact, messing with xhost is usually very bad for
security. Just connect with the -X switch, which you're probably
already doing.

TsanChung

unread,
Oct 8, 2009, 9:51:26 AM10/8/09
to
On Oct 7, 7:51 pm, Allen Kistler <ackist...@oohay.moc> wrote:
> TsanChung wrote:
> > On the root shell of Konsole on ubuntu 8.04.
> > #DISPLAY=localhost:0.0
> > # xclock
> > Error: Can'topendisplay: localhost:0.0

> > # gvim /etc/fstab
> >E233:cannotopendisplay
> > Press ENTER or type command to continue
> > # kdesudo gvim /etc/fstab
> > kdesudo:cannotconnect to X server

>
> > # xhost + localhost
> > xhost:  unable toopendisplay"localhost:0.0"
>
> > #DISPLAY=:0.0

> > # xclock
> > Invalid MIT-MAGIC-COOKIE-1 keyError: Can'topendisplay: :0.0
> > #DISPLAY=:0
> > # xclock
> > Invalid MIT-MAGIC-COOKIE-1 keyError: Can'topendisplay: :0

>
> You'll get that error if /etc/hosts defines only 127.0.0.1 as localhost,
> but you're connected over IPv6.  Edit /etc/hosts so that BOTH 127.0.0.1
> and ::1 are defined as localhost.
>
> Since you're apparently connected via ssh, you really shouldn't have to
> mess with xhost.  In fact, messing with xhost is usually very bad for
> security.  Just connect with the -X switch, which you're probably
> already doing.

I followed your instructions to edit /etc/hosts as follows but the
problem still exists.
127.0.0.1 localhost
::1 localhost
127.0.1.1 tc-desktop

# The following lines are desirable for IPv6 capable hosts
#::1 ip6-localhost ip6-loopback
...

I am using gvim on the root shell of Konsole on ubuntu 8.04, I am not
using ssh. I experiment with xhost because I want to solve the
"cannot open display" problem.

Allen Kistler

unread,
Oct 8, 2009, 4:53:22 PM10/8/09
to
TsanChung wrote:
> On Oct 7, 7:51 pm, Allen Kistler <ackist...@oohay.moc> wrote:
>> TsanChung wrote:
>>> On the root shell of Konsole on ubuntu 8.04.
>>> #DISPLAY=localhost:0.0
>>> # xclock
>>> Error: Can'topendisplay: localhost:0.0
>>>
>>> [snip]
>>>
>>
>> [snip]

>>
>
> I followed your instructions to edit /etc/hosts as follows but the
> problem still exists.
> 127.0.0.1 localhost
> ::1 localhost
> 127.0.1.1 tc-desktop
>
> # The following lines are desirable for IPv6 capable hosts
> #::1 ip6-localhost ip6-loopback
> ...
>
> I am using gvim on the root shell of Konsole on ubuntu 8.04, I am not
> using ssh. I experiment with xhost because I want to solve the
> "cannot open display" problem.

Sorry. I missed your mention of Konsole the first time. I got
distracted by DISPLAY=localhost:0.0.

So now I'm wondering why you set DISPLAY. It should have already been
:0.0 (i.e., no localhost hostname), which is the correct value for
someone at the console.

If you just open a terminal window and "echo $DISPLAY" then what do you
get? If you don't set DISPLAY first, does xclock or gvim give an error
then? They should just work without changing DISPLAY.

TsanChung

unread,
Nov 20, 2009, 7:30:51 PM11/20/09
to
On Oct 8, 3:53 pm, Allen Kistler <ackist...@oohay.moc> wrote:
> TsanChung wrote:
> > On Oct 7, 7:51 pm, Allen Kistler <ackist...@oohay.moc> wrote:
> >> TsanChung wrote:
> >>> On the root shell of Konsole on ubuntu 8.04.
> >>> #DISPLAY=localhost:0.0
> >>> # xclock
> >>> Error: Can'topendisplay: localhost:0.0
>
> >>> [snip]
>
> >> [snip]
>
> > I followed your instructions to edit /etc/hosts as follows but the
> > problem still exists.
> > 127.0.0.1       localhost
> > ::1             localhost
> > 127.0.1.1       tc-desktop
>
> > # The following lines are desirable for IPv6 capable hosts
> > #::1     ip6-localhost ip6-loopback
> > ...
>
> > I am using gvim on the root shell of Konsole on ubuntu 8.04,  I am not
> > using ssh.  I experiment with xhost because I want to solve the
> > "cannotopendisplay" problem.

>
> Sorry.  I missed your mention of Konsole the first time.  I got
> distracted byDISPLAY=localhost:0.0.
>
> So now I'm wondering why you setDISPLAY.  It should have already been

> :0.0 (i.e., no localhost hostname), which is the correct value for
> someone at the console.
>
> If you justopena terminal window and "echo $DISPLAY" then what do you
> get?  If you don't setDISPLAYfirst, does xclock or gvim give an error

> then?  They should just work without changingDISPLAY.

I use Konsole 1.6.6 on KDE 3.5.10 & kubuntu 8.04.
The regular (non-root) console on Konsole is ok:
$ echo $DISPLAY
:0
$ xclock

The root console on Konsole cannot start xclock:
# echo $DISPLAY

ugn...@gmail.com

unread,
Jul 15, 2013, 2:27:19 AM7/15/13
to
How to solve E233, please? Thanks a lot. :-)

Bill Marcum

unread,
Jul 15, 2013, 5:01:38 AM7/15/13
to
The error message "cannot open display" usually means the DISPLAY
variable is not set.

ugn...@gmail.com

unread,
Jul 15, 2013, 6:05:57 AM7/15/13
to
I see, but E233 still available after %setenv DISPLAY XXX, %echo $DISPLAY. Thanks.

ugn...@gmail.com

unread,
Jul 15, 2013, 6:11:07 AM7/15/13
to
Okay, I find correct DISPLAY variable now. Thanks. :)

On Monday, July 15, 2013 5:01:38 PM UTC+8, Bill Marcum wrote:

kevinpa...@gmail.com

unread,
Jul 9, 2019, 3:08:11 AM7/9/19
to
If you have this problem after some time when running with -X arg. or just ForwardX11 in /etc/ssh/ssh_config, then run $ ssh username@hostname -Y, to enable trusted X11 forwarding, don't know the exact cause but I'm guessing with -X some features expire after some time, probably to increase security.

Source: https://superuser.com/a/827617/986827
0 new messages