LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-28-2007, 08:55 PM   #1
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Rep: Reputation: 15
How to run a Gtk application as a user with root privs?


From my research it isn't possible to use suid for Gtk applications. There seems to be possible to execute Gtk applications as a user with root privileges using "PAM". I'd like to know what you think is the best way to achieve it. This is to run gnome-ppp. Please let me know how you would do. Thanks.
 
Old 10-28-2007, 09:24 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
"gksu" is probably the command you're looking for. "sudo" should also work.

Last edited by indienick; 10-28-2007 at 09:37 PM.
 
Old 10-29-2007, 06:27 AM   #3
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Original Poster
Rep: Reputation: 15
But they both ask for my root password
 
Old 10-29-2007, 07:27 AM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
If you set up sudo properly, it should be asking for your password, not roots.
 
Old 10-30-2007, 06:17 AM   #5
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Original Poster
Rep: Reputation: 15
Yes, sorry, this is what I meant. But I don't want to have to type any password... How could I do it?
 
Old 10-30-2007, 07:23 AM   #6
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
You set up sudo to not ask for a password. If you look in the sudoers file, you should see examples of how to use the NOPASSWD directive. If that is set up properly, the user is allowed to use that command without supplying a password. For example, if you set up the shutdown command like this:

usename = NOPASSWD: /sbin/shutdown

It would allow the user to shut down the computer with sudo shutdown and not have to enter a password.

Have a look in the sudoers man page for more examples.
 
Old 11-02-2007, 09:40 AM   #7
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Original Poster
Rep: Reputation: 15
Unhappy

Thanks. Since that day, I've tried to add myself in the sudoers using this man page: http://www.gratisoft.us/sudo/man/sudoers.html but I don't understand very well, it's a little complicated to me!

I added this to /etc/sudoers:

Code:
werner                gnome-ppp = NOPASSWD: /usr/sbin/gnome-ppp
But then when I type:
Code:
sudo /usr/sbin/gnome-ppp
It asks for my password (which I don't want). And then I get an error message:
Code:
sudo /usr/sbin/gnome-ppp
(gnome-ppp:11258): Gtk-WARNING **: cannot open display:
Any idea?
Thanks.
 
Old 11-02-2007, 01:34 PM   #8
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
werner gnome-ppp = NOPASSWD: /usr/sbin/gnome-ppp
You're right, sudo syntax is a little bit on the thick side.

Part of the problem might be that first gnome-ppp. That is in the position of an alias, which means that you had to have defined it earlier in the sudoers file. You might be able to get by with:

werner NOPASSWD: /usr/sbin/gnome-ppp
 
Old 11-02-2007, 02:34 PM   #9
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks, when I do this, I get this error message while saving the file:
Quote:
# visudo -f /etc/sudoers
>>> sudoers file: syntax error, line 49 <<<
What now?
Any idea?
Thanks.
 
Old 11-03-2007, 06:39 AM   #10
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
That rhythmic banging sound you hear is me banging my head on the keyboard. Sudo syntax always drives me nuts. I think the problem is that I forgot to define a machine where the command was legit to use.

So this might work:

werner ALL = NOPASSWD: /usr/sbin/gnome-ppp


In this case, the ALL refers to all machines on your network, but that is probably OK for a personal machine. An alternative would be to define a specific machine and then use that name:

Host_Alias MYMACHINE = 127.0.0.1
werner MYMACHINE = NOPASSWD: /usr/sbin/gnome-ppp


In this case, you would only have the rights on this particular machine. Again, if this is a standalone machine, using this instead of ALL is probably a distinction without a difference. You might have to use the actual IP address of your machine (or a range if you're using DHCP) if the 127.0.0.1 doesn't work.
 
Old 11-12-2007, 01:49 PM   #11
werner1975
Member
 
Registered: Jun 2007
Posts: 43

Original Poster
Rep: Reputation: 15
Thank you. I tried it and now when I do "sudo gnome-ppp" as a user, I get "Gtk-Wraning **: Cannot open display:"
Any idea?
Thanks.
 
Old 11-12-2007, 02:44 PM   #12
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Yeah, that is X security kicking in. Basically, X is telling you that root doesn't have the authority/privilege to put something on your X display. There are two ways to allow this, xhost and xauth.

Xhost is the cheap and sleazy way of doing it as it controls X access on a per-host basis. So if you first run xhost localhost on the command line before you run your sudo gnome-ppp, it should allow root to display it. Now the warning: xhost localhost allows anyone on localhost to use your X display. On a single user machine, this probably isn't a real big deal. In a multiuser environment, it is a big breach of security and you don't want to do it.

The alternative is xauth, which allows you to authorize specific users with a cookie. It is kind of complicated (which is why most people use xhost on single user machines) but there is a good explanation here.
 
Old 11-12-2007, 02:44 PM   #13
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,513

Rep: Reputation: 63
Quote:
Originally Posted by werner1975 View Post
Thank you. I tried it and now when I do "sudo gnome-ppp" as a user, I get "Gtk-Wraning **: Cannot open display:"
Any idea?
Thanks.
That looks like X not wanting to let root open the display try something like below changing to your normal username in your /root/.bashrc file.

Code:
## allows me to run an X program as root

export XAUTHORITY=/home/stephen/.Xauthority
 
Old 11-12-2007, 02:59 PM   #14
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,781
Blog Entries: 1

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
Originally Posted by HappyTux View Post
That looks like X not wanting to let root open the display try something like below changing to your normal username in your /root/.bashrc file.

Code:
## allows me to run an X program as root

export XAUTHORITY=/home/stephen/.Xauthority
I didn't think it was that simple, but then again I'm no authority on xauth. Does sudo actually pick up roots .bashrc?
 
Old 11-12-2007, 03:14 PM   #15
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,513

Rep: Reputation: 63
Quote:
Originally Posted by Hangdog42 View Post
I didn't think it was that simple, but then again I'm no authority on xauth. Does sudo actually pick up roots .bashrc?
Looks like it must be if it was running as normal user you would not get the error that looks like the one you get when trying as root su'd from a user account therefore under the users X session.
 
  


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
Compile and run gtk application under SunOS and use it with Hummingbird exceed in win dream2code Solaris / OpenSolaris 6 04-12-2007 05:34 AM
mysql 5 backup user privs michaelsanford Programming 0 04-01-2006 04:56 PM
How to enable root to run graphical application in user log in xgreen Slackware 4 03-07-2005 06:39 AM
Assign Privs to specific user sikandar Linux - Software 13 08-31-2003 02:12 AM
I can run application with root Rex_chaos Linux - General 5 03-28-2002 01:48 PM


All times are GMT -5. The time now is 08:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration