5

I am logged as user A. I want to run a GUI application as user B. User, not root. User B is local too, not remote, I only need different environment variables. I don't want to run the second X, I want them on the same display. I have no problem with programs running in terminal, the su - ... works. For graphical there is an error message:

Application initialization failed: couldn't connect to display ":0.0"

or

Gtk-WARNING **: cannot open display: :0.0

Is there a good way to fix it? The article about correct using of xhost or something?

  • man xhost indicates that xhost +userBname should work. – mouviciel Apr 30 '13 at 8:41
  • It only returns xhost: bad hostname "userBname" – Michas Apr 30 '13 at 9:15
  • @Michas use xhost + then, disabling acl – daisy Apr 30 '13 at 9:17
  • 1
    How about su - user_b and then set DISPLAY variable to :0.0, for example: DISPLAY=":0.0" xterm &? – roomcays Apr 30 '13 at 9:40
  • @warl0ck Well, it works. I don't think it is good to set this for everyone, though. – Michas Apr 30 '13 at 9:49
5

Run the following command to give userBname access to the display:xhost +SI:localuser:userBname You may use xhost + to give access to everybody; however this is insecure. Better is to give access on a per-user basis. The correct syntax for xhosts entries for local users is SI:localuser:username.

Then su userBname, export DISPLAY=:0.0, and finally run your GUI program. Although you granted access to the display earlier with xhost, you must also set the environmental variable DISPLAY so that programs know where to place their graphical output. Allowing different DISPLAY variables for different users allows multiple users connected to a single machine to use different physical terminals.

  • It works. It looks I don't have to set DISPLAY variable. – Michas May 2 '13 at 7:42
1

Just use gksu -u desired username, enter the Password, and you should be ready to go.

DISPLAY=:1.0 gksu [-u <user>] [options] <command>

Alternatively you could use su and then set XDISPLAY to the right screen and finally start your desired application.

  • It doesn't work for me, the same error. – Michas May 2 '13 at 7:39
  • What does echo $DISPLAY return? – Alessandro Meyer May 2 '13 at 7:41
  • It returns :1.0, the same for main and second user. I had to kill X. – Michas May 2 '13 at 7:45
  • I updated the command, does it work with DISPLAY prepended? – Alessandro Meyer May 2 '13 at 7:50
  • It doesn't work. The error is the same. – Michas May 2 '13 at 8:08
0

This is how I accomplish this:-

  1. Open an x-terminal as the user with the existing X session.
  2. Issue the command xauth list. You should see the X Magic cookie values that authenticate requests to the X-server, for various descriptors. Copy the one with the "unix" reference. e.g. myhost/unix: MIT-MAGIC_COOKIE-1 df8923ae98098fb890c63454c7c
  3. Open a 2nd terminal as the initial user but switch user (su) to the id you want e.g. su - user2
  4. Now you have switched user, issue the command xauth add and paste the line you previously copied at stage 2, then hit return e.g. xauth add myhost/unix: MIT-MAGIC_COOKIE-1 df8923ae98098fb890c63454c7c
  5. Start an X program in the 2nd terminal from the commandline e.g.: firefox

That's it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.