An X program needs two pieces of information in order to connect to an X display.
It needs the address of the display, which is typically :0
when you're logged in locally or :10
, :11
, etc. when you're logged in remotely (but the number can change depending on how many X connections are active). The address of the display is normally indicated in the DISPLAY
environment variable.
It needs the password for the display. X display passwords are called magic cookies. Magic cookies are not specified directly: they are always stored in X authority files, which are a collection of records of the form “display :42
has cookie 123456
”. The X authority file is normally indicated in the XAUTHORITY
environment variable. If $XAUTHORITY
is not set, programs use ~/.Xauthority
.
See Open a window on a remote X display (why "Cannot open display")? for more details.
In your case, DISPLAY
is set but programs evidently cannot find the cookie file. Check the value of XAUTHORITY
in your session and under su
.
If XAUTHORITY
is not set in your session and su
sets the HOME
environment variable to root's home directory, then you need to set XAUTHORITY
to /home/msz/.Xauthority
where /home/msz
is your home directory.
If su
removes XAUTHORITY
from the environment, either put it back, or configure su
not to do this.
If your home directory is on some filesystems like NFS, root may not be able to read it directly. In that case, you can copy the .Xauthority
file to a different location on a non-NFS filesystem:
XAUTHORITY_COPY=$(umask 077; mktemp)
cat "${XAUTHORITY:-~/.Xauthority}" "$XAUTHORITY_COPY"
XAUTHORITY="$XAUTHORITY_COPY" su
rm "$XAUTHORITY_COPY"
unset XAUTHORITY_COPY
export $(dbus-launch)
or usexhost [+]
to be able to launch programs using X and your superuser account. – 41754 Jan 31 '14 at 09:23$ xhost
to see the current access and$ xhost +
to enable access from any host. You often do this from a virtual terminal you know for sure that can spawn programs using X. – 41754 Jan 31 '14 at 09:42echo $DISPLAY
show? Which user does the xserver process, you want to use, belong to? (you can find out the latter by using for exampleps faux
) – Bananguin Jan 31 '14 at 09:49xhost
should be run from inside the X server as the user who is running the X session. Is that root as well? – njsg Jan 31 '14 at 10:35xhost +
is the equivalent of "opening a huge security hole big enough for anyone to drive a bus through". – Jenny D Jan 31 '14 at 11:41xhost +
might on some setups, but if it does, you don't want to use it: it means “allow anybody to do anything with my account”.) – Gilles 'SO- stop being evil' Jan 31 '14 at 22:39xhost +
exposes root and user login passwords as long as samba passwords. And God kills 314 kittens too. – 41754 Feb 01 '14 at 17:19