4

I am developing a software in Qt in which I created a terminal. I run different commands through QProcess in that but when I run root commands it ask for password in terminal. I tried to run via sudo but it only accepts password in terminal. Is there any way to give password from another source like pop up widget or a text file?

Ilya
  • 4,583
  • 4
  • 26
  • 51
Noor
  • 99
  • 2
  • 12

3 Answers3

4

I have created a QProcess with "bash" as program.

Then just write to it:

echo mypassword | sudo -S ifconfig eth0 192.168.1.123\n
Tom
  • 4,257
  • 6
  • 33
  • 49
3

You could try

  • Running your application as root (which is really a very bad idea, actually!)
  • Edit sudoers file and add the commands you want to run to this file. Then you can run these commands like sudo run_x_cmd with no password i.e, your QProcess can run these commands and you won't be asked for password.
ramtheconqueror
  • 1,907
  • 1
  • 22
  • 35
  • The sudoers file is a good method, but ideally, a separate user should be created for the application and only the processes it requires to be run should be added to the sudoers file. Even better would be to factor out the privileged processes to another application, separating it from the user's interface and adding that to the sudoers file. – TheDarkKnight Aug 18 '15 at 09:27
  • Thanks for your suggestions i found my problem solution here http://stackoverflow.com/questions/23322739/how-to-execute-complex-linux-commands-in-qt – Noor Aug 19 '15 at 04:09
0

Adding a password to a text file in order to source input for the command is a very bad idea, as it weakens security.

Version 1.8 of sudo provides a plugin architecture, which would allow you to link to it from your application and may provide a solution for you.

The SDK for the sudo plugin API can be found in the documentation .

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85