グラフィカルアプリケーションでpkexecがgksudoよりも優先されるのはなぜですか?


10

:反駁はこのことをUbuntuの資料を提供してくださいhttps://help.ubuntu.com/community/RootSudoなぜ、私の完全に更新13.04システム上で、pkexec機能しませんか?

$ pkexec gedit somefile.txt
No protocol specified

** (gedit:13135): WARNING **: Could not open X display
Cannot open display: 
Run '/usr/bin/gedit --help' to see a full list of available command line options


pkexecは、gksuに代わるものではありません。このように手動で実行することは想定されていません。
psusi 2013年

2
私はgksuについて質問したり言及したりしませんでした。
chili555 2013年

pkexec構成せずに実行GUIを作成することについての非常に良い答え:askubuntu.com/a/332847/89385
akostadinov

policykit-1-gnomeをインストールします。参照してくださいここに詳細と説明について。
user303371 2017

回答:


7

なぜ動作しないのですか?

デフォルトでpkexecは、グラフィカル(X11)アプリケーションを実行できません。manページから:

 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


3
それで、グラフィカルアプリケーションの場合、pkexecではなくgksudoが推奨されますか?
chili555 2013年

1
たぶんそうだ。gksudo利用できる場合は、使用する必要がある各アプリに対して単一のアクションを作成する代わりに、それを使用する方がはるかに簡単です(「グローバルな」方法がない場合)。
セーラム

1
@ Salem-では、なぜ私の回答が編集され、pkexecを使用するように承認されたのか、それがグラフィカルアプリケーションでの使用を意図しておらず、ご覧のとおり機能しなかったのかと思います。askubuntu.com/questions/313619/…わからないことがあるはずです。
chili555 2013年

@ chili555その編集が質問の動機となった場合は、Metaで質問する必要があります。13.04では、インストールgksudoまたは構成する必要がありますpkexec(使用することもできますsudo -iが、Alt + F2(別名「実行」)では機能しません)。最初の方がずっと簡単だと思います。誰かが別の方法でうまく考えている場合...私には、意図したとおりに機能しないものを提案するのは間違っているようですが、何か不足している可能性があります...
セーラム

1
pkexec実際に構成なしでGUIを実行できます:askubuntu.com/a/332847/89385
akostadinov
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.