首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >何时使用pkexec与gksu/gksudo?

何时使用pkexec与gksu/gksudo?
EN

Ask Ubuntu用户
提问于 2011-11-11 20:44:07
回答 3查看 36.3K关注 0票数 83

有两种通用的方法可以图形化地以根用户的身份运行应用程序(或者更普遍地说,以另一个用户的身份运行)。像gksugksudokdesudo这样的程序是sudo的图形前端。相反,pkexecPolicyKit的图形前端。

当以根用户的身份手动运行程序(或以另一个非根用户的身份)时,与使用pkexec前端的传统方法相比,使用sudo有哪些优缺点(如果有的话)?

EN

回答 3

Ask Ubuntu用户

回答已采纳

发布于 2011-11-12 15:35:14

PolicyKit是更可配置的,尽管pkexec没有利用这种可配置性。此外,pkexec还向用户显示将要启动的程序的完整路径,从而使用户更加确定会发生什么。PolicyKit的所谓“策略”可以用来设置更多的高级设置,例如是否应该记住密码。

我从pkexec手册上得到的东西:

程序将运行它的环境将被设置为一个最小的已知和安全的环境,以避免通过LD_LIBRARY_PATH或类似机制注入代码。此外,PKEXEC_UID环境变量被设置为调用pkexec的进程的用户id。因此,pkexec将不允许您以另一个用户的身份运行例如X11应用程序,因为没有设置$DISPLAY环境变量。

pkexec手册中有关策略或行动定义的更多信息:

To specify what kind of authorization is needed to execute the program /usr/bin/pk-example-frobnicate as another user, simply write an action definition file like this <?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/policyconfig.dtd"> <policyconfig> <vendor>Examples for the PolicyKit Project</vendor> <vendor\_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor\_url> <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate"> <description>Run the PolicyKit example program Frobnicate</description> <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description> <message>Authentication is required to run the PolicyKit example program Frobnicate</message> <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate</message> <icon\_name>audio-x-generic</icon\_name> <defaults> <allow\_any>no</allow\_any> <allow\_inactive>no</allow\_inactive> <allow\_active>auth\_self\_keep</allow\_active> </defaults> <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate> </action> </policyconfig> and drop it in the /usr/share/polkit-1/actions directory under a suitable name (e.g. matching the namespace of the action). Note that in addition to specifying the program, the authentication message, description, icon and defaults can be specified. For example, for the action defined above, the following authentication dialog will be shown: [IMAGE][2] +----------------------------------------------------------+ | Authenticate [X] | +----------------------------------------------------------+ | | | [Icon] Authentication is required to run the PolicyKit | | example program Frobnicate | | | | An application is attempting to perform an | | action that requires privileges. Authentication | | is required to perform this action. | | | | Password: [\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_] | | | | [V] Details: | | Command: /usr/bin/pk-example-frobnicate | | Run As: Super User (root) | | Action: org.fd.pk.example.pkexec.run-frobnicate | | Vendor: Examples for the PolicyKit Project | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+ If the user is using the da\_DK locale, the dialog looks like this: [IMAGE][3] +----------------------------------------------------------+ | Autorisering [X] | +----------------------------------------------------------+ | | | [Icon] Autorisering er påkrævet for at afvikle | | PolicyKit eksemplet Frobnicate | | | | Et program forsøger at udføre en handling der | | kræver privilegier. Autorisering er påkrævet. | | | | Kodeord: [\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_] | | | | [V] Detaljer: | | Bruger: Super User (root) | | Program: /usr/bin/pk-example-frobnicate | | Handling: org.fd.pk.example.pkexec.run-frobnicate | | Vendor: Examples for the PolicyKit Project | | | | [Annullér] [Autorisering] | +----------------------------------------------------------+ Note that pkexec does no validation of the ARGUMENTS passed to PROGRAM. In the normal case (where administrator authentication is required every time pkexec is used), this is not a problem since if the user is an administrator he might as well just run pkexec bash to get root. However, if an action is used for which the user can retain authorization (or if the user is implicitly authorized), such as with pk-example-frobnicate above, this could be a security hole. Therefore, as a rule of thumb, programs for which the default required authorization is changed, should never implicitly trust user input (e.g. like any other well-written suid program).

票数 28
EN

Ask Ubuntu用户

发布于 2012-10-26 12:47:07

使用sudo,您可以在sudo的上下文中设置每个用户和每个程序是否保留或重置调用者环境的策略。默认情况下设置env_reset策略。

如果不显式地配置pkexec,就不能通过pkexec运行图形应用程序。因为这仅仅是环境重置的结果,所以对于sudo也是如此。但是,无论是pkexec还是sudo都不能阻止恶意应用程序作为root用户运行,从而从显示管理器或用户X11-cookie文件中检索所有必要的信息。后者,两者或相似,甚至可以由非根应用程序执行,视情况而定。

Sudo不需要明确的用户列表。列出任何用户组,甚至为所有用户设置权限都是可以完成的。target_pw指令允许这些用户在他们希望运行应用程序(即root )的上下文中使用用户的凭据进行身份验证。除此之外,同样传统的su (su / gtksu / kdesu)程序也可以在没有特殊配置的情况下进行同样的操作。

sudo也允许用户在指定的时间内保持身份验证。该选项名为timeout,可全局配置,每个用户或每个应用程序。身份验证可以保留在每个tty中,也可以在每个用户的全局范围内保留。

虽然pkexec可能不验证传递给程序的参数,但sudo确实具有此特性。尽管你承认,你很容易就会搞砸这件事,但这通常是不可能的。

您可以通过pkexec:图标、文本显示来稍微调整一下程序的运行方式,甚至可以有本地化的东西等等。视情况而定,这确实是很好的做法。然而,令人难过的是,有人觉得有必要为这一特性重新发明轮子。这可能是要放到图形gtksudo/kdesu包装中的东西。

Policykit只是一个集中的配置框架。不幸的是不是个漂亮的。PKs XML-文件比任何应用程序提供的二进制文件都要复杂得多。没有人会这么愚蠢地使用二进制..。噢,天哪.不要紧。

票数 15
EN

Ask Ubuntu用户

发布于 2011-11-15 22:59:27

pkexecsudo及其前端有几个不同之处:

  1. 如果不显式地配置图形应用程序,就不能通过pkexec运行图形应用程序。
  2. 您可以稍微调整一下通过pkexec运行程序的方式:图标、显示的文本、是否记住密码、是否允许程序以图形方式运行等等。
  3. 任何人都可以以超级用户的身份运行"Run“(只要他们能够这样进行身份验证),使用sudo,您必须在sudoers文件中被列为admin。
  4. gksudo在询问密码时锁定键盘、鼠标和焦点,而pkexec没有。在这两种情况下都是不过,击键是可以闻的。
  5. 使用pkexec时,您的工作环境要稍微清洁一些。

例如:

代码语言:javascript
复制
cd /etc/init.d
sudo cat README
# and now the same with pkexec
pkexec cat README
# nice, huh?
票数 8
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/78352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档