<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Enter admin rights once, use it in multiple process calls to terminal [Linux]]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I have a lot of process calls that runs commands in the terminal. This is done by calling the following line multiple times:</p>
<pre><code>process.start("pkexec", QStringList() &lt;&lt; "--user" &lt;&lt; "root" &lt;&lt; [command]);
</code></pre>
<p dir="auto">This works, but it's not very convenient as the user gets a prompt to enter admin password every time these processes run.</p>
<p dir="auto">So my question is, how should i do if i only want the user to enter admin rights once and still get root privileges  multiple times?<br />
Thanks.</p>
]]></description><link>https://forum.qt.io/topic/98545/enter-admin-rights-once-use-it-in-multiple-process-calls-to-terminal-linux</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Nov 2026 15:51:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/98545.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Jan 2019 11:09:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Wed, 16 Jan 2019 09:23:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fleppe">@<bdi>fleppe</bdi></a><br />
And there was I thinking <code>pkexec</code> was something to do with running some <code>pkzip</code> command.....</p>
<p dir="auto">This "polkit" stuff is all very good, and if that's what you want to use fine.  But it's going to require a bit of setting up to use.  I do not know how much configuring you want to do, or how "secure" you need to be for your purposes.</p>
<p dir="auto">I will just say that in terms of "simplicity", if that's really what you want, my two thoughts would be:</p>
<ul>
<li>
<p dir="auto">Use <code>sudo</code> and rely on what I quoted from the man page to ensure the user only gets prompted for password once every 15 minutes, if that works for you.</p>
</li>
<li>
<p dir="auto">Use <em>setuid</em>.  It sounds like all your commands are <code>apt update</code>s?  I would not make your Qt program itself setuid (unless you really know what you are doing).  Rather, a tiny executable wrapper program supplied with your Qt app to just do <code>apt update</code> with setuid would suffice (installed with just <code>chown root</code> &amp; <code>chmod u+s</code>).  I would <em>suggest</em> this might be the simplest solution if you want to avoid any password prompting at all, as per your original question.  Have you at least considered/do you know about <em>setuid</em>, even if you have good reason to reject it?</p>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/505096</link><guid isPermaLink="true">https://forum.qt.io/post/505096</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 16 Jan 2019 09:23:08 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Wed, 16 Jan 2019 05:15:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Yes, the &amp;&amp; between sudo and first command is not needed, I was in hurry when I wrote my first comment in this thread.</p>
]]></description><link>https://forum.qt.io/post/504995</link><guid isPermaLink="true">https://forum.qt.io/post/504995</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 16 Jan 2019 05:15:55 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Tue, 15 Jan 2019 20:07:36 GMT]]></title><description><![CDATA[<p dir="auto">Good idea to put the commands in a text file, thought the problem is that i need to do stuff in the QT-application in between command calls.</p>
<p dir="auto"><code>pkexec </code>as i understand is: "A application used to interface with the polkit actions and authenticate an application to acquire root access." So that's a part of getting root access. <a href="https://stackoverflow.com/questions/47885043/proper-method-to-acquire-root-access-on-linux-for-qt-applications" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/47885043/proper-method-to-acquire-root-access-on-linux-for-qt-applications</a></p>
<p dir="auto">Think of it as i calling <code>sudo apt update</code> multiple times in the program and doing things in the QT application in between.</p>
<p dir="auto">I'm grateful for your answers.<br />
Thanks.</p>
]]></description><link>https://forum.qt.io/post/504936</link><guid isPermaLink="true">https://forum.qt.io/post/504936</guid><dc:creator><![CDATA[fleppe]]></dc:creator><pubDate>Tue, 15 Jan 2019 20:07:36 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Tue, 15 Jan 2019 15:03:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a><br />
I could be wrong, but if you try a command like you say which goes</p>
<pre><code>sudo &amp;&amp; pkexec ...
</code></pre>
<p dir="auto">I would <em>imagine</em> that, since each segment separated by <code>&amp;&amp;</code>s (or whatever similar) is run its own separate sub-shell, the <code>sudo</code>'s "lifetime" will only be its own sub-shell, and therefore assuming your intention was to run the later <code>pkexec ...</code> on the command-line under <code>sudo</code> (that was what you were intending, right?) it will in fact have "been &amp; gone", leaving the <code>pkexec ...</code> running <em>not</em> as <code>sudo</code> after all...</p>
<p dir="auto">To be clear: not trying to nit-pick on you, I too am not always 100% and like to learn, am just trying to produce a heads-up clarification for <a class="plugin-mentions-user plugin-mentions-a" href="/user/fleppe">@<bdi>fleppe</bdi></a> if he tries yours and it doesn't work.</p>
<p dir="auto">As I said earlier, I would expect</p>
<pre><code>process.start("sudo " + pkexec_command)
</code></pre>
<p dir="auto">to correctly run the <code>pkexec</code> as <code>sudo</code>.</p>
<p dir="auto">However, unless OP has marked his <code>sudo</code> to require no password (as I do, on my own machine), this <em>might</em> prompt for <code>sudo</code> credentials each time for each <code>pkexec</code>, which he says he wishes to avoid?  From <code>man sudo</code> I think this approach relies on:</p>
<blockquote>
<p dir="auto">Security policies may support credential caching to allow the user to run<br />
sudo again for a period of time without requiring authentication.  The<br />
sudoers policy caches credentials for 15 minutes, unless overridden in<br />
sudoers(5).  By running sudo with the -v option, a user can update the<br />
cached credentials without running a command.</p>
</blockquote>
<p dir="auto">If that is no good, one solution would be: Assuming you know what multiple <code>pkexec</code>s you wish to execute, send them all off to a text file as separate commands and run that file once via <code>sudo</code>.</p>
]]></description><link>https://forum.qt.io/post/504883</link><guid isPermaLink="true">https://forum.qt.io/post/504883</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 15 Jan 2019 15:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Tue, 15 Jan 2019 14:33:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> There is -c in my "example".<br />
&amp;&amp; is simply to chain several commands in one command line (com1 &amp;&amp; com2 &amp;&amp; com3...).<br />
But now I realised that this --user parameter is for the pkexec command (whatever it is), so my suggestion isn't valid.</p>
]]></description><link>https://forum.qt.io/post/504872</link><guid isPermaLink="true">https://forum.qt.io/post/504872</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 15 Jan 2019 14:33:29 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Tue, 15 Jan 2019 12:25:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a><br />
I'm a little lost looking at your proposed command line.  I don't see any <code>-c</code>, I don't know what the first occurrence of <code>&amp;&amp;</code> is about, I don't know how you're quoting/joining into one command, etc.  Possibly fixed font would make it clearer....  Also, by the time you're <code>sudo</code>-ing, do we need the <code>--user root</code> any longer?</p>
<p dir="auto">If all you're suggesting to OP is to use <code>sudo</code>, that accepts the command as-is on the line.  So what about something like:</p>
<pre><code>process.start("sudo " + command)
</code></pre>
<p dir="auto">(There are various ways of passing arguments separately/together, each have their advantages/disadvantages.  To be clear I'm using the straightforward <code>QString</code> overload.  There may be quoting issues, but yours will have those too.)</p>
]]></description><link>https://forum.qt.io/post/504840</link><guid isPermaLink="true">https://forum.qt.io/post/504840</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 15 Jan 2019 12:25:57 GMT</pubDate></item><item><title><![CDATA[Reply to Enter admin rights once, use it in multiple process calls to terminal [Linux] on Tue, 15 Jan 2019 11:48:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fleppe">@<bdi>fleppe</bdi></a> You could execute "sh" as command with "-c" parameter + "sudo" + "&amp;&amp;" + "pkexec", QStringList() &lt;&lt; "--user" &lt;&lt; "root" &lt;&lt; [command]) + "&amp;&amp;" ... (all other commands).</p>
]]></description><link>https://forum.qt.io/post/504834</link><guid isPermaLink="true">https://forum.qt.io/post/504834</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 15 Jan 2019 11:48:22 GMT</pubDate></item></channel></rss>