2

I'm writing a GUI program, that configures your systems settings. For this purpose, the whole program should not be ran as root, otherwise it would configure the system for the root user. However, there is a subprocess command that needs to be ran as root, and I'm not sure how to safely, and properly incorporate this into my GUI for the following reasons.

  1. The user would almost have to enter it into the GUI frontend.
  2. I'm not sure how to verify that the users password was indeed correct. How to add error proofing to alert the user that the password is incorrect, without just letting the command fail miserably.
  3. How to run this safely, since the users password is going to be involved.

I've been reccomended to create a daemon, and pass commands to that. This seems like a bit overkill, since it's just one command that needs to be ran. And since the user can't just type this into the terminal, it needs to be handled by the frontend of the GUI.

Does anyone have any other ideas on how to incorporate this feature?

2
  • 1
    How about using pkexec? Commented Jan 5, 2014 at 5:33
  • @falsetru That would work! Commented Jan 5, 2014 at 5:36

1 Answer 1

2

You can use pkexec.

For example:

proc = subprocess.Popen(['/usr/bin/pkexec', command])
Sign up to request clarification or add additional context in comments.

7 Comments

What if I need to run multiple commands as root? pkexec asks for the password each time, unlike sudo which "caches" it for a certain amount of time. Is there a way I can achieve similar results using pkexec?
@Seth How about combine pkexec with sh -c ...?
@Seth, subprocess.Popen(['/usr/bin/pkexec', 'sh', '-c', 'command1; command2']) or subprocess.Popen(['/usr/bin/pkexec', 'sh', '-c', 'command1 && command2'])
@falsetru Sadly that won't work well with the exact situation I am in, but I believe I found the answer over here. Not exactly the answer I wanted, but the correct answer nevertheless. Thanks anyway!
@Seth, How about post a question with your situation (and an answer if you found a solution that works for you) ? :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.