LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-09-2008, 01:12 PM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 1,389

Rep: Reputation: 101Reputation: 101
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
 
Old 10-09-2008, 01:54 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by taylorkh View Post
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
 
Old 10-09-2008, 05:10 PM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 1,389

Original Poster
Rep: Reputation: 101Reputation: 101
Thanks David1357. However, I still get the "cannot open display" error message.

Ken
 
Old 10-10-2008, 03:42 AM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by taylorkh View Post
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.
 
Old 10-10-2008, 09:01 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
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.
 
Old 04-17-2011, 01:37 AM   #6
kjbinstl
LQ Newbie
 
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
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!

Last edited by kjbinstl; 04-17-2011 at 01:40 AM.
 
Old 04-17-2011, 04:18 AM   #7
tommcd
Senior Member
 
Registered: Jun 2006
Location: Philadelphia PA USA
Distribution: Lubuntu, Slackware
Posts: 2,230

Rep: Reputation: 291Reputation: 291Reputation: 291
Quote:
Originally Posted by kjbinstl View Post
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!

Last edited by tommcd; 04-17-2011 at 04:20 AM.
 
Old 04-17-2011, 04:20 AM   #8
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
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.
 
Old 04-18-2011, 07:54 PM   #9
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu question jbob0124 Linux - Newbie 22 03-22-2008 01:09 PM
A question about Ubuntu 7.04 Xstar Linux - Desktop 7 06-19-2007 09:47 AM
Ubuntu question Viper1991 Linux - Software 5 10-17-2006 02:50 AM
Question about Ubuntu v.5.04 Night Hawk One Linux - Newbie 2 11-15-2005 01:32 AM
ubuntu question chash Linux - Software 2 04-05-2005 01:26 AM


All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration