यह काम क्यों नहीं करता है?
डिफ़ॉल्ट रूप से pkexecआपको ग्राफ़िकल (X11) एप्लिकेशन चलाने की अनुमति नहीं देता है। मैन पेज से:
The environment that PROGRAM will run it, will be set to a minimal
known and safe environment in order to avoid injecting code through
LD_LIBRARY_PATH or similar mechanisms. In addition the PKEXEC_UID
environment variable is set to the user id of the process invoking
pkexec.
As a result, pkexec will not allow you to run X11 applications
as another user since the $DISPLAY and $XAUTHORITY environment
variables are not set.
These two variables will be retained if the
org.freedesktop.policykit.exec.allow_gui annotation on an action is set
to a nonempty value; this is discouraged, though, and should only be
used for legacy programs.
जैसा कि मैन पेज में कहा गया है, आप इसे काम कर सकते हैं, हालांकि मैं वास्तव में नहीं जानता कि यह किसी तरह खतरनाक है या अनुशंसित है ।
उदाहरण के लिए gedit को सक्षम करने के लिए आप /usr/share/polkit-1/actions/com.ubuntu.gedit.policyनिम्नलिखित सामग्री बना सकते हैं :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<vendor>gedit</vendor>
<vendor_url>gedit</vendor_url>
<icon_name>accessories-text-editor</icon_name>
<action id="org.freedesktop.policykit.pkexec.gedit">
<description>Run "gedit"</description>
<message>Authentication is required to run Text Editor</message>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/gedit</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>
फिर pkexec geditउम्मीद के मुताबिक काम करना चाहिए:

जैसा कि आप अनुमान लगा सकते हैं, यह केवल geditकाम करेगा । सिद्धांत रूप में, यदि आपने allow_gui"org.freedesktop.policykit.exec" (डिफ़ॉल्ट क्रिया) में जोड़ा है, तो यह सभी अनुप्रयोगों के लिए काम करना चाहिए, लेकिन मेरे परीक्षणों में मुझे आपके जैसा ही परिणाम मिला।
क्यों पसंद किया जाता है pkexec?
यहाँ आप की ताकत के बारे में चर्चा पा सकते हैं pkexec।