From: TsanChung on
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...(a)ponder.sky.com> wrote:
> TsanChung <tsanchung.w...(a)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
> sudo gvim
>
> --
> |   spi...(a)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..."  |

From: Allen Kistler on
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.
From: TsanChung on
On Oct 7, 7:51 pm, Allen Kistler <ackist...(a)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.
From: Allen Kistler on
TsanChung wrote:
> On Oct 7, 7:51 pm, Allen Kistler <ackist...(a)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.