Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Execute multiple root privileged commands using single password prompt

Execute multiple root privileged commands using single password prompt

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dylan Holt
    wrote on last edited by
    #1

    Hello guys, I'm using QT in Linux. Is it possible to take user password once using pkexec to execute multiple root privileged commands in QProcess? Or is there a way to start the entire project as root?

    jsulmJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      not really a Qt specific question, but...QProcess executes a single process in the privilege context of the Qt application. To escalate the privilege the QProcess executable should either be suid root or execute a batch file using something like sudo.

      as to pkexec, I will withhold comment on that because I have nothing good to say about polkit, systemd, pulsaudio, or any other the other window-esque things that have been shoved down the throat of the linux users.

      D JonBJ 2 Replies Last reply
      2
      • Kent-DorfmanK Kent-Dorfman

        not really a Qt specific question, but...QProcess executes a single process in the privilege context of the Qt application. To escalate the privilege the QProcess executable should either be suid root or execute a batch file using something like sudo.

        as to pkexec, I will withhold comment on that because I have nothing good to say about polkit, systemd, pulsaudio, or any other the other window-esque things that have been shoved down the throat of the linux users.

        D Offline
        D Offline
        Dylan Holt
        wrote on last edited by
        #3

        @Kent-Dorfman Thank you for the replay. I'm new to QT can you please give an example how I could get user privilege in a proper way? Also is there a way to run the project as root at the beginning?

        Pablo J. RoginaP 1 Reply Last reply
        0
        • D Dylan Holt

          @Kent-Dorfman Thank you for the replay. I'm new to QT can you please give an example how I could get user privilege in a proper way? Also is there a way to run the project as root at the beginning?

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by Pablo J. Rogina
          #4

          @Dylan-Holt said in Execute multiple root privileged commands using single password prompt:

          Also is there a way to run the project as root at the beginning?

          If you mean running your project from Qt Creator with root privileges (although it doesn't sound like a good idea, you've been warned...), you can do:

          sudo /your/path/to/qtcreator
          

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          D 1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @Dylan-Holt said in Execute multiple root privileged commands using single password prompt:

            Also is there a way to run the project as root at the beginning?

            If you mean running your project from Qt Creator with root privileges (although it doesn't sound like a good idea, you've been warned...), you can do:

            sudo /your/path/to/qtcreator
            
            D Offline
            D Offline
            Dylan Holt
            wrote on last edited by Dylan Holt
            #5

            @Pablo-J.-Rogina said in Execute multiple root privileged commands using single password prompt:

            If you mean running your project from Qt Creator with root privileges (although it doesn't sound like a good idea, you've been warned...), you can do:

            sudo /your/path/to/qtcreator
            

            No, I asked if there a way to make the app request root permission when we deploy the project and start the app as root. Like Gparted which asks for root permission when we launch it.

            JonBJ 1 Reply Last reply
            0
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6

              What you are asking for is traditionally a suid root application. It is the way in the UNIX world that system commands can execute privileged functions when necessary. Setting it up is easy and there is ample information online as to how to do it...doing it securely and correctly is another matter. I strongly suggest reading up on design of system utilities before simply making a program privileged. The first step is always to evaluate whether you really need root privilege and to avoid it if at all possible. assuming it IS NECESSARY, you need to do a full cyber security analysis of your program to see if it is susceptible to attacks, and then (only then) you use system calls to immediately drop privilege when the program is executed and only elevate privilege in the specific parts of the program where it is necessary to do a protected function, dropping privilege again immediately after.

              1 Reply Last reply
              2
              • D Dylan Holt

                Hello guys, I'm using QT in Linux. Is it possible to take user password once using pkexec to execute multiple root privileged commands in QProcess? Or is there a way to start the entire project as root?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Dylan-Holt Maybe this can help: https://stackoverflow.com/questions/11714868/qt-make-program-ask-for-user-elevation-at-executionwindows

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • Kent-DorfmanK Kent-Dorfman

                  not really a Qt specific question, but...QProcess executes a single process in the privilege context of the Qt application. To escalate the privilege the QProcess executable should either be suid root or execute a batch file using something like sudo.

                  as to pkexec, I will withhold comment on that because I have nothing good to say about polkit, systemd, pulsaudio, or any other the other window-esque things that have been shoved down the throat of the linux users.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Kent-Dorfman

                  as to pkexec, I will withhold comment on that because I have nothing good to say about polkit, systemd, pulsaudio, or any other the other window-esque things that have been shoved down the throat of the linux users.

                  That is interesting to hear. I come from old-skool setuid times, so this polkit stuff is new to me and I see people talking about it in these forums when asking about elevation. Sounded complex, and requires set-up. Nice to know you don't rate it :)

                  1 Reply Last reply
                  0
                  • D Dylan Holt

                    @Pablo-J.-Rogina said in Execute multiple root privileged commands using single password prompt:

                    If you mean running your project from Qt Creator with root privileges (although it doesn't sound like a good idea, you've been warned...), you can do:

                    sudo /your/path/to/qtcreator
                    

                    No, I asked if there a way to make the app request root permission when we deploy the project and start the app as root. Like Gparted which asks for root permission when we launch it.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @Dylan-Holt
                    Your original question was:

                    Is it possible to take user password once using pkexec to execute multiple root privileged commands in QProcess?

                    That is rather different from:

                    I asked if there a way to make the app request root permission when we deploy the project and start the app as root.

                    If you need root only for executing some OS commands from your app, you should be careful about taking root permission on your app as your solution, unless you really know what you're doing.... In any case, if your Qt app has a GUI you may have problems running it as root, depending on your Linux variant/configuration.

                    There is a way to satisfy your initial question. You could prompt for root password once in your Qt UI and then leverage the -S argument to sudo to run commands without having to re-prompt for the password. Whether this is advisable is another matter, but it answers your original question. There is also the -A argument, but support is not always present, and it would re-prompt each time. There was a question I answered in this forum a while ago where a dev wanted to prompt only once but run multiple sudo commands.

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved