LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A question about su in Ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/a-question-about-su-in-ubuntu-675342/)

taylorkh 10-09-2008 12:12 PM

A question about su in Ubuntu
 
Here is the situation... The PC is logged on as a non-sudoer (the wife's account) and I need to make a little tweak to lets say /etc/fstab. If I open a terminal window and type "gksu gedit /etc/fstab" it will not work as her account is not on the sudoers list.

So in the terminal window I issue the command "su ken" and enter my password. I, a sudoer, am now logged on within the terminal window. I then issue the command "gedit /etc/fstab" and I receive the following error message:
Quote:

No protocol specified
cannot open display
Of course I can edit the file with vi or switch user and logon with my account with sudoer rights. The real question is - can a currently logged on user su to another user account and execute a graphical program as the second user?

Thanks,

Ken

David1357 10-09-2008 12:54 PM

Quote:

Originally Posted by taylorkh (Post 3305362)
I, a sudoer, am now logged on within the terminal window. I then issue the command "gedit /etc/fstab" and I receive the following error message:

Try
Code:

$ export DISPLAY=localhost:0.0
$ gedit /etc/fstab


taylorkh 10-09-2008 04:10 PM

Thanks David1357. However, I still get the "cannot open display" error message.

Ken

David1357 10-10-2008 02:42 AM

Quote:

Originally Posted by taylorkh (Post 3305530)
However, I still get the "cannot open display" error message.

I reckon you will have to force the issue:
Code:

$ sudo gedit /etc/fstab
Since you used su to become a user with sudo privileges, that should work.

estabroo 10-10-2008 08:01 AM

It's because you don't have permission, you'd need to copy the current user's .Xauthority file to your/root's directory. When you did the su ken, if you didn't use a - then as ken you could run X apps because you are still using the previous user's environment, however when you did the sudo for the gedit you switched to the root user and are using root's environment which won't have proper permission without that .Xauthority file. You might also be able to issue an xhost + to open up X's permissions, just remember to turn them back off when your done.

kjbinstl 04-17-2011 12:37 AM

any solutions?
 
I have the same problem as the original poster here. Is there no solution?
I tried the "export" [etc.] suggestion, but I get command not found. Do I have to install some package to be able to run the "export" command?
I tried logging myself on with su -p kevin, but even though that preserves the non-sudoer's environment, or at least the environment variables I know about, I still am denied when I try to run any graphical program e.g. "gedit" with no filename.
I tried "xhost [my computer name" before su'ing, but that doesn't work either.
Help? Ken & I can't be the only people with this problem.
Thanks!

tommcd 04-17-2011 03:18 AM

Quote:

Originally Posted by kjbinstl (Post 4326839)
I have the same problem as the original poster here. Is there no solution?

Perhaps this tutorial about creating a "browse as root" launcher will help:
http://www.psychocats.net/ubuntucat/rootlauncher/
Also, the first comment at the bottom of that tutorial offers another possible solution.

And welcome to the LQ fourms!

dudeman41465 04-17-2011 03:20 AM

gksudo or gksu usually lets me run X applications as root inside my regular user's session just fine.

i.e.
Code:

gksudo gedit somefile.txt
Edit: You may have to install gksudo for it to work; if I remember correctly it isn't installed by default in Ubuntu.

estabroo 04-18-2011 06:54 PM

looks like the easiest way (but not a secure as using an xauth method) is just to

xhost local:

which gives everyone on the box accessing X locally via the unix socket (not tcp) permission to use the X server.

then just
xhost -local:

to turn it back off


All times are GMT -5. The time now is 03:18 AM.