Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"


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

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

share|improve this question
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 – warl0ck Apr 30 '13 at 9:17
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
up vote 4 down vote accepted

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.

share|improve this answer
It works. It looks I don't have to set DISPLAY variable. – Michas May 2 '13 at 7:42

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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