Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I switch user in a terminal.

su bob

I can't open gedit because bob doesn't own the display.

If I execute

xhost +

before switching to bob I can open the display for some applications but not all. I get the following output when trying to execute gedit:

(crashreporter:4415): GnomeUI-WARNING *: While connecting to session manager: None of the authentication protocols specified are supported.
*
GLib-GIO:ERROR:/build/buildd/glib2.0-2.28.6/./gio/gdbusconnection.c:2279:initable_init: assertion failed: (connection->initialization_error == NULL)

share|improve this question
1  
Try command line editors like nano. –  Oxwivi Jun 28 '11 at 13:08
    
@Oxwivi Sure, and I do use nano a lot but in this case gedit is just one of the GUI applications I wasn't able to open. –  z7sg Jun 28 '11 at 13:30
    
The only program you can't open as another user? You should include it in the question. –  Oxwivi Jun 28 '11 at 13:38
    
Try to avoid xhost + if you're on a networked computer, as that disables X security and gives anyone on the network permission to connect to your X display and do things like reading your keyboard from remote... –  Riccardo Murri Jun 28 '11 at 13:46
    
@Oxwivi It could also be firefox, that doesn't work either, it's just in general, I want to be able to do this. gedit was a poor example, you are right about that. –  z7sg Jun 28 '11 at 13:50

2 Answers 2

up vote 3 down vote accepted

If you want to allow user bob to access your existing X session from the command line, you can enter these commands at the terminal prompt:

xauth nextract - $DISPLAY | sudo -u bob xauth nmerge -

Thius uses the xauth command to extract the authentication information for the current user (first part of the command, before the |) and then merge it into user bob's $HOME/.Xauthority file. Note that it requires /etc/sudoers to be configured so that you are allowed to run commands as user bob (this is the default if you're the admin user on a Ubuntu box).

You can then switch to user bob with su -l.

Alternatively, you can issue these separate commands:

xauth nextract - $DISPLAY > /tmp/xauth.temporary.file
su -l bob -c 'xauth nmerge - < /tmp/xauth.temporary.file'
rm /tmp/xauth.temporary.file

Note that:

1) the temporary file must have permissions such that user bob can read it (which often means that any user on the system can read it);

2) there is a time window during which any user that can read the temporary file can get access to your X display.

Therefore, it is better to use the sudo approach as it does not have these downsides.

share|improve this answer
    
I got this to work, but: su: must be run from a terminal –  z7sg Jun 28 '11 at 13:34
    
@z7sg: Yes, of course it must be run in a terminal. Isn't that what your question is about? How to switch to another user in a terminal and still be able to launch X applications from that same terminal? –  Riccardo Murri Jun 28 '11 at 13:44
    
@Ricardo Yes, but su doesn't like being run from a pipe. It's a security issue. –  z7sg Jun 28 '11 at 13:47
    
@z7sg Oh, I see. You're right, but you can use sudo instead of su and not run into this problem. I'll edit my answer with details. –  Riccardo Murri Jun 28 '11 at 14:03
    
From my desktop running xubuntu, I run ssh -X otherhost. From that host, DISPLAY is "localhost:10.0". When I try xauth extract - $DISPLAY I get an error, No matches found, authority file "-" not written –  djb Nov 26 '13 at 20:25

Another way, after xhost + has been executed:

dbus-launch gedit --sm-client-disable
share|improve this answer

Your Answer

 
discard

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.