尝试system-config-users从命令行启动时,我收到以下警告,并且该工具未打开。我正在使用 CentOS 7 和 Mate 1.8.1。
警告**:枚举操作时出错:GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: 名称 org.freedesktop.PolicyKit1 未由任何 .service 文件提供
错误检查授权 org.freedesktop.policykit.exec: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: 名称 org.freedesktop.PolicyKit1 未由任何 .service 文件提供
yum 列表 polkit*
Installed Packages
polkit.x86_64 0.112-5.el7 @anaconda
polkit-devel.x86_64 0.112-5.el7 @base
polkit-docs.noarch 0.112-5.el7 @base
polkit-gnome.x86_64 0.105-6.el7 @epel
polkit-pkla-compat.x86_64 0.1-4.el7 @anaconda
Run Code Online (Sandbox Code Playgroud)
我的系统缺少什么导致此错误?
我看到最近的 GNU/Linux 正在使用 ConsoleKit 和 PolicyKit。它们是为了什么?它们是如何工作的?
最好的答案应该解释每个人试图解决什么样的问题,以及他们如何设法解决它。
我是 GNU/Linux 的长期用户,从那时起这些东西还不存在。我一直在使用 Slackware 和最近的 Gentoo。我是一名高级用户/管理员/开发人员,所以答案可以(并且应该!)尽可能详细和准确。我想了解这些东西是如何工作的,这样我就可以以最好的方式使用它们(作为用户或开发人员)。
很长一段时间以来,我一直在反对这一点。它与这个问题有关。我想知道当我选择从 GUI 关闭我的 Linux 机器时会发生什么。这似乎记录不佳(如果有的话)。
理想情况下,我希望得到一个与 DE 和 OS 无关的答案。除此之外,我对运行 Gnome 的 Mandriva 2010.1 和 Debian 6.x (Squeeze) 和 7.0 (Wheezy) 的具体情况感兴趣。(如果你密切关注,是的,那就是 Gnome 2 和 Gnome 3)
基本上,我想知道当我按“关闭”或“重新启动”时启动了哪个命令/脚本/脚本序列,以便我可以修改它们的行为。我看过的一些论坛帖子建议进行黑客攻击,/etc/polkit-1/*但例如,这个目录结构只是我的 Debian (Squeeze) 机器上的一个骨架。
任何人都可以帮忙吗?
编辑
到目前为止我尝试过的
shutdown用我自己的脚本替换了可执行文件。这不起作用:当我按下shutdownGnome 时,不执行我的脚本就注销了。/usr/share/menu,没什么帮助。解决方案的可能途径
strace使用 GUI 选项(这甚至可能吗?)shutdown的源代码gnome-session的源代码更新
根据我对下面答案的评论,我查看了下面的polkit操作/usr/share/polkit-1/actions/并发现(在文件中org.freedesktop.consolekit.policy)一个称为org.freedesktop.consolekit.system.stop-multiple-users抛出消息的操作
System policy prevents stopping the system when other users …Run Code Online (Sandbox Code Playgroud) 我创建了一些基本有效的 systemd 服务:
地点:
/etc/systemd/system/multi-user.target.wants/publicapi.service
Run Code Online (Sandbox Code Playgroud)
内容:
[Unit]
Description=public api startup script
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=-/etc/environment
WorkingDirectory=/home/techops
ExecStart=/home/techops/publicapi start
ExecStop=/home/techops/publicapi stop
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
当我尝试在命令行中以 techops 用户身份重新启动服务时,我得到以下输出:
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'publicapi.service'.
Multiple identities can be used for authentication:
1. Myself,,, (defaultuser)
2. ,,, (techops)
Choose identity to authenticate as (1-2):
Run Code Online (Sandbox Code Playgroud)
我希望只有 techops 可以重新启动服务,并且我希望在以 techops 身份登录时不出现此提示。我怎样才能做到这一点?
我读到 polkit-1 或 sudoers 有不同的方法,但我不确定。
[更新] 2019-01-27 4:40pm
感谢您对 Thomas 和 Perlduck 的全面回答。它帮助我提高了对 systemd 的了解。
按照无密码提示启动服务的方法,我要道歉,我没有足够强调真正的问题:
实际上,对我来说最重要的是,除了 techops 之外,没有其他用户应该停止或启动该服务。但至少使用前两种方法我仍然可以运行service …
我正在运行 CentOS 7.2;见下文:
# systemctl stop firewalld
Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)
Failed to stop firewalld.service: Connection timed out
Failed to get load state of firewalld.service: Connection timed out
Run Code Online (Sandbox Code Playgroud)
journalctl 只是报如下错误: [system] Failed to activate service 'org.freedesktop.PolicyKit1': timed out
我正在阅读Linux 内核开发一书,在第 5 章“系统调用实现”第 77 页中说
例如,capable(CAP_SYS_NICE) 检查调用者是否有能力修改其他进程的nice 值。默认情况下,超级用户拥有所有功能,而非root 用户不拥有。例如,这里是 reboot() 系统调用。注意它的第一步是如何确保调用进程具有 CAP_SYS_REBOOT 。如果删除了那个条件语句,则任何进程都可以重新启动系统。
但是,在我的 Debian Sid 中,我可以通过使用 gnome 或通过执行 /sbin/reboot 而不使用 sudo 或 su 来重新启动我的机器。这怎么可能?
也许用systemctl?
ls -l /sbin/reboot
lrwxrwxrwx 1 root root 14 Jun 28 04:23 /sbin/reboot -> /bin/systemctl
Run Code Online (Sandbox Code Playgroud)
编辑:我的用户组
[damian@xvz:~]$ groups
damian sudo wireshark bumblebee
Run Code Online (Sandbox Code Playgroud)
编辑 2:systemctl 权限
[damian@xvz:~]$ ls -l /bin/systemctl
-rwxr-xr-x 1 root root 626640 Jun 28 04:23 /bin/systemctl
Run Code Online (Sandbox Code Playgroud) 我已经禁用了 slim 和 lightdm,而是使用 startx。几乎一切正常,除了在以非 root 用户身份登录时我无法控制与 NetworkManager 的网络连接。启用网络和启用 Wifi 显示为灰色。如果我转到“编辑连接”并选择任一连接,“编辑”按钮将灰显。我已经使用 root 用户进行了测试,它确实有效。
我写了一个应该解决这个问题的 polkit 规则,但它没有。我创建的文件 /etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules 包含:
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("netdev")) {
return polkit.Result.YES;
}
});
Run Code Online (Sandbox Code Playgroud)
我的用户 ID 是 netdev 组的成员。我的系统是 Debian Sid,我的 DE 是 LXDE。我的 ~/.xinitrc 包含:
exec ck-launch-session dbus-launch /usr/bin/startlxde
Run Code Online (Sandbox Code Playgroud)
我几乎整天都在与这个斗争。谁能解释我做错了什么?
我需要以与桌面环境无关的方式检查我是否有可用的 polkit 代理。
现在,我正在做的是检查 polkit 代理是否正在运行,使用如下代码:
ps aux | grep some-polkit-agent
Run Code Online (Sandbox Code Playgroud)
some-polkit-agent可能在哪里:
polkit-gnome-authentication-agent-1 (对于 gnome2 和 gnome3-fallback)polkit-kde-authentication-agent-1 (对于 kde)polkit-mate-authentication-agent-1 (给伴侣)lxpolkit (对于 lxde)“无后备” gnome3(gnome-shell)在 gnome-shell 进程本身中有自己的 polkit 代理,所以我无法 ps-grep 它。我假设的是,如果gnome-shell正在运行,则 polkit 代理就位。
当系统hidepid启用时就会出现问题(参见http://www.linux-dev.org/2012/09/hide-process-information-for-other-users/)。这种安全措施使 aps不会向我显示任何正在运行的 polkit 代理,即使有。
有没有更好的方法可以检查可用的 polkit 代理?
我正在使用 Ubuntu 16.04。
有一个文件位于 /usr/share/polkit-1/actions/org.freedesktop.login1.policy似乎控制有关关机/挂起/休眠选项的权限。
在此文件中,相关选项采用以下格式:
<defaults>
<allow_any>no</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
Run Code Online (Sandbox Code Playgroud)
对应于每个动作(关机、暂停等)。
这是该文件的完整版本。
我想知道allow_any,allow_inactive和allow_active选项的含义。
它们究竟是什么意思?
我好奇的原因是我想在没有 root(来自 cron)的情况下以非交互方式休眠,但我收到了授权错误。
而这些错误似乎可以通过修改这个文件来解决。
在 CentOS 5 的旧时代,我有一个以另一个用户身份运行的应用程序。我创建了一个 .desktop 文件,它运行如下命令:
gksu -u anotheruser someapplication
Run Code Online (Sandbox Code Playgroud)
当用户单击该图标时,弹出窗口要求输入“另一个用户”的密码,当密码正确时,“某个应用程序”启动。
现在,在 CentOS 7 的现代,我找不到这种行为的替代品。我尝试过beesu:
beesu -l -P someapplication anotheruser
Run Code Online (Sandbox Code Playgroud)
但它要求我输入 root 密码而不是“另一个用户”密码。
我也尝试过 pkexec:
pkexec --user anotheruser someapplication
Run Code Online (Sandbox Code Playgroud)
结果相同。
这两种方法在寻找正确的显示变量时也存在问题:
Failed to parse arguments: Cannot open display:
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
谢谢。