为什么pkexec比gksudo更喜欢图形应用程序?

请提供反驳此内容的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不允许您运行图形(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

    gedit gedit accessories-text-editor  Run "gedit" Authentication is required to run Text Editor  auth_admin auth_admin auth_admin  /usr/bin/gedit true   

那么pkexec gedit应该按预期工作:

在此处输入图像描述

你可以猜到,这只会使gedit工作。 理论上,如果您将allow_gui添加到“org.freedesktop.policykit.exec”(默认操作),这应适用于所有应用程序,但在我的测试中,我得到的结果与您的相同。

为什么pkexec更喜欢?

在这里你可以找到关于pkexec优势的pkexec