Important: Please read the Qt Code of Conduct -

How to make Qprocess run a command line as Root

  • Hi all!
    I'm trying to execute a comando as root user, using QProcess!
    I ask user for password and will add to command line... how It's possible?

    The command can use "su" or "sudo" to execute...
    Thanks all.

  • You should give the executable "setuid/gid" permission. You can do this by invoking this command:
    @chmod +s ./executable@

    Read more at:

    But be warned that if this process gets exploited, the whole system may be compromised. There is a chance that you can do what you want to do without setuid.

  • I need to add all users on the system to a group...
    I use this command:

    awk -F: '$3 > 999 {print $1}' /etc/passwd | xargs -I USERNAME sudo usermod -a -G dialout USERNAME

  • Save the command to a shell script file and give it +s permission. Run the shell script using whatever means you can in your application, and it should be ok. But beware, if someone changes the shellscript to destroy your system, you will be in trouble, because he may do whatever root can do. So, place the file in appropriate location and revoke write permisson from it for all users except root. I think this should work:

    @sudo chown root:root
    sudo chmod 4755

    Be sure to read these articles on setuid before actually using it:

  • If its possible I would like to set my code inside the compiled code, "hard coded" script... In this way I will not have any problems, I guess...

  • It was already discussed on this forum. With details and at least 2 possible solutions with source code for testing. Please use search functions of this forum before you create new topic. Maybe you problem is already solved.

    Topic I'm talking about: "[SOLVED]Is it possible to pass on password to process requiring root privileges":

Log in to reply