After inputting the su command, the X application does not run.

After inputting the su command, the X application does not run.

You may get the following error messages when running an X application, such as xterm, after switching users.

xterm Xt error: Can't open display: or X connection to localhost:10.0 broken (explicit kill or server shutdown).



When using an Xapplication through the SSH protocol, there are two important things which need to be checked. They are typically automatically configured by the SSH server. But when switching to another user, they need to be manually configured by the user.

  • DISPLAY variable.

  • Cookie for user authorization.



To make the configurations manually, follow the steps below:

  1. Figure out the DISPLAY of the user who first logged in and take note of it.

    $ echo $DISPLAY localhost:11.0

    The localhost may be the host name of systems. The number '11.0' may be another number depending on the system status.


  2. Copy the .Xauthority file of the user's home directory to /tmp.

    $ copy ~/.Xauthority /tmp/myXauth $ chmod 666 /tmp/myXauth
  3. Switch to the desired user.

    $ su a_user_you_want_to_switch_to
  4. Set the DISPLAY variable from step 1 and designate the file containing the cookies.

    $ export DISPLAY=localhost:11.0 $ export XAUTHORITY=/tmp/myXauth
  5. Run the desired X application.

    $ xterm &

You can preserve the previous user environment by using the su command with the -m parameter or no parameter. In certain systems, this will preserve the DISPLAY variable and cookie information. And in other systems, it will not transfer the DISPLAY variable or the cookie information or neither.