Can't connect to X server after su !!! 

Newsgroups: comp.os.linux.misc,comp.os.linux.x
Date: Thu, 16 Jan 2003 16:30:32 GMT
> First I login as one user at int the XDM login window to start the X server,
> everything is OK.
> Then, in an Xterm, I use the ``su'' command to change to another user( another
> common user, or even root ). But I can not run any X client now. The
> error message is:
>
>      Xlib: connection to ":0.0" refused by server
>      Xlib: Client is not authorized to connect to Server
>      Error: Can't open display: :0.0

The original user "owns" the Xserver, and any other user cannot connect to it without authorization. There are several 'workarounds'. One is to use 'xhost' to disable access control (for the world—dangerous if you're on a network which contains strangers; for 'localhost'—probably okay if no others can log in to your local machine; using 'xauth' to obtain a magic cookie from the owner of the Xserver, and placing it in the 'cookie jar' of the other user—see "Remote-X-Apps mini-HOWTO".)

Dave Brown

Can't connect to X server after su !!! 

> The original user "owns" the Xserver, and any other user cannot connect to
> it without authorization.  There are several 'workarounds'.  One is to use

Or, two other options:

  1. See if your distro has the command "sux" which is su+x.
  2. Put these lines in root's .bashrc:
if [ "$USER" != "root" ] ; then
     export XAUTHORITY=`eval echo ~$USER/.Xauthority`
fi

That should fix it. I copied this from someone else, so I'm not a guru.

Soft Edges

Can't connect to X server after su !!! 

>xhost +

Thank you. Please report to the duty torturer. A little something off the ears I think.

If you must do this, at least do "xhost +localhost" to avoid creating a security hole larger than you could get an elephant through.

Even better, enable X forwarding in ssh and do "ssh -l root localhost".

John