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.

I login as user 'foo' and if I am able to run gedit and edit files in my Ubuntu 12.04 machine with a DISPLAY setting as :0

If I "su - bar" and then try to edit files, I get a no protocol specified error and it doesn't open the necessary files. What coule be the problem here?

share|improve this question
1  
Possible duplicate: askubuntu.com/questions/5410/… –  Flint Jul 12 '12 at 5:35

3 Answers 3

gedit is a graphical program, so just as you would not run it as root with straight sudo, you shouldn't run it as another user with straight sudo or straight su.

Instead, if you (i.e., foo) have the power to run programs as another user with sudo, this is probably the easiest way for footo run gedit as bar:

xhost +local:bar
gksu -u bar gedit

If you don't have the power to run programs as another user with sudo but you can su to bar, then this is the easiest way:

gksu -w -u bar gedit

The -w flag (equivalent to --su-mode) makes gksu (which is a frontend for both sudo and su) use su instead of sudo.

  • You shouldn't need to run any corresponding xhost command to make gksu -w ... work.

If you want a graphical terminal instance (gnome-terminal) from which you can run anything as bar including graphical applications, you should consider just running a new instance of gnome-terminal as bar (which you can do the same way as running gedit, detailed above).

share|improve this answer
    
I find that I need to first run 'xhost +' to make this work with users who are not root. –  Mark Paskal Jul 13 '12 at 3:27
    
@MarkPaskal I don't have the ability to test it with and without that right now ...so please feel free to edit my answer to incorporate that information into the instructions, if you wish! –  Eliah Kagan Jul 13 '12 at 3:28
    
I have just tested it. Your instructions using gksu -w work but for sudo do not. I will edit. –  Mark Paskal Jul 13 '12 at 3:36
    
@MarkPaskal Cool--thanks for your help and effort in improving this answer! –  Eliah Kagan Jul 13 '12 at 3:37
    
You're welcome. :) –  Mark Paskal Jul 13 '12 at 3:45

you ca do this by

ssh -l Other-User -X localhost gedit

there is an new window run on your desktop, but with environment of "Other-User"!

I have tested this with Ubuntu 10.04 LTS on my box!

share|improve this answer

The syntax you provide doesn't look right. If you want to switch to user 'bar', then I believe you should use "su bar". But if that's not right, I would think you would get an error at the time you try to switch users. Maybe it's a typo in your question or su takes it anyway.

I think it's more likely that the problem is gedit is a gui-based editor and so is trying to launch in that user's x session, which wouldn't exist if you change changed users via the terminal. What happens if you use "vi file_to_edit"? Vi is a terminal-based editor and shouldn't be affected by gui difficulties.


edit: I need to get some computer glasses, I thought the command you put was "su -bar". But "su - bar" is valid syntax.

share|improve this answer
    
As a side note, if you want to edit files via the terminal as another user, vi is a terrible choice. Use vim or emacs. I just gave that as an example because it is installed with Ubuntu by default. –  user76496 Jul 12 '12 at 5:27
    
I am on Ubuntu 12.04 OS on my desktop and I am using a terminal to open files. (su - bar or su bar) doesn't seem to make any difference and I don't want to use vi or vim. gedit would be preferable, but I still see an error related to DISPLAY while launching gedit as a different user than the logged in user. –  user352290 Jul 12 '12 at 5:44
    
In this situation I think a terminal-based editor is your best bet. If I were you I wouldn't want to use vi or vim either - personally, I think emacs is a far superior choice. Nano is also an ok option (looks like that is also a installed by default). I'm not aware of a way to launch a gui-based application as another user, but if anyone else is, I'd love to hear it. –  user76496 Jul 12 '12 at 6:57
    
@user76496 You can launch a GUI application as another user (whether that user be root, or another non-root user). –  Eliah Kagan Jul 12 '12 at 12:54

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.