Unable to run gedit as a different user
Solution 1
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 foo
to 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 makegksu -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).
Solution 2
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!
Related videos on Youtube
user352290
Updated on September 18, 2022Comments
-
user352290 over 1 year
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?
-
Admin almost 12 yearsPossible duplicate: askubuntu.com/questions/5410/…
-
-
user76496 almost 12 yearsAs 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.
-
user352290 almost 12 yearsI 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.
-
user76496 almost 12 yearsIn 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.
-
Eliah Kagan almost 12 years@user76496 You can launch a GUI application as another user (whether that user be root, or another non-root user).
-
Eliah Kagan almost 12 years@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!
-
jalkoby almost 12 yearsI have just tested it. Your instructions using gksu -w work but for sudo do not. I will edit.
-
Eliah Kagan almost 12 years@MarkPaskal Cool--thanks for your help and effort in improving this answer!