experchange > linux.setup

TsanChung (08-30-09, 10:52 PM)
"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 (08-30-09, 11:02 PM)
On Aug 30, 4:52 pm, TsanChung <tsanchungw> 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


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

# echo $DISPLAY
# sudo echo $DISPLAY
Andrew Halliwell (08-30-09, 11:11 PM)
TsanChung <tsanchung.wong> 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
Nico Kadel-Garcia (08-30-09, 11:22 PM)
On Aug 30, 5:11 pm, Andrew Halliwell <spi> wrote:
> TsanChung <tsanchungw> wrote:
> 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 (08-31-09, 01:08 AM)
Nico Kadel-Garcia <nkadel> 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).
TsanChung (10-07-09, 11:40 PM)
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> wrote:
[..]
Allen Kistler (10-08-09, 01:51 AM)
TsanChung wrote:
[..]
> # 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 (10-08-09, 03:51 PM)
On Oct 7, 7:51 pm, Allen Kistler <ackist> wrote:
> TsanChung wrote:
> 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 (10-08-09, 10:53 PM)
TsanChung wrote:
[..]
> 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 (11-21-09, 02:30 AM)
On Oct 8, 3:53 pm, Allen Kistler <ackist> wrote:
> TsanChung wrote:
> 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
:0
# xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0
ugnuos (07-15-13, 08:27 AM)
How to solve E233, please? Thanks a lot. :-)

On Monday, August 31, 2009 4:52:39 AM UTC+8, TsanChung wrote:
[..]
Bill Marcum (07-15-13, 11:01 AM)
On 07/15/2013 02:27 AM, ugnuos wrote:
> How to solve E233, please? Thanks a lot. :-)
> On Monday, August 31, 2009 4:52:39 AM UTC+8, TsanChung wrote:

The error message "cannot open display" usually means the DISPLAY
variable is not set.
ugnuos (07-15-13, 12:05 PM)
I see, but E233 still available after %setenv DISPLAY XXX, %echo $DISPLAY. Thanks.

On Monday, July 15, 2013 5:01:38 PM UTC+8, Bill Marcum wrote:
[..]
ugnuos (07-15-13, 12:11 PM)
Okay, I find correct DISPLAY variable now. Thanks. :)

On Monday, July 15, 2013 5:01:38 PM UTC+8, Bill Marcum wrote:
[..]
kevinpatel4400 (07-09-19, 09:08 AM)
On Monday, August 31, 2009 at 2:22:39 AM UTC+5:30, TsanChung 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


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:
Similar Threads