详解polkitd

polkitd是一个在Linux系统中广泛使用的授权管理守护进程,它的作用是轻松控制用户进程对系统资源进行访问和操作。

一、polkitd用户

polkitd以系统用户的身份运行,通常是以root或polkitd用户身份运行。在CentOS 7中,polkitd用户是由系统会话服务处理的,而在CentOS 8中,polkitd用户则默认由polkitd包提供。

polkitd用户通常是被设计用来运行polkitd守护进程的用户,它拥有对系统资源的高权限访问权,因此在保护系统安全方面具有重要作用。当用户请求对系统资源进行访问操作时,polkitd会检查该用户所属组是否具有合适的权限,从而决定是否授权。

二、polkitd进程占用CPU高

有时,用户可能会发现polkitd进程会消耗很多CPU资源,这通常是由于polkitd正在进行授权检查过程。为了避免这种情况,可以采取以下措施:

1、禁用polkitd的debug模式,这通常可以通过在/etc/polkit-1/polkitd.conf配置文件中修改debug选项来实现。警告:禁用debug模式可能导致polkitd运行异常,因此必须小心谨慎。

[debug]
# Enable/disable debugging
#debug=no
debug=yes #改为no

2、尽量减少需要进行授权检查的操作。这可以通过审查程序的代码、减少程序的调用次数以及在可能的情况下缓存已通过授权检查的结果等方式来实现。

三、polkitd相关配置

polkitd的配置文件通常位于/etc/polkit-1/目录下。重要的配置文件包括:

1、polkitd.conf:polkitd的主配置文件,包括运行模式、授权验证策略、debug选项等。

[General]
# This is a comment
# A comment can appear anywhere on a line
# Comments start with a hash symbol.

# Here, we define a new constant:
# We use this constant later to check if a client is a member
# of the wheel group, and we grant the client the admin
# authentication level if it is.
const=wheel_check,check_group(wheel)

# Uncomment this to enforce the same authentication requirements for
# every action
#DefaultAuthentication=auth_admin

# In addition to authentication, authorization is required to
# execute privileged actions. In situations where authorization
# precedes authentication, you can change the control flow by
# setting this variable.
#PrioritizeAuthorization=0

# Define the authentication agent(s) that will be used for obtaining
# passwords or challenges.
#DefaultAuthenticationAgent=pkexec

# Define the authorization agent(s) that will be used for obtaining
# authorization decisions.
#DefaultAuthorizationAgent=org.freedesktop.policykit.exec

# The following controls which users can access the system via Polkit
# Please note that enabling this is not a good idea due to security
# reasons.
# AllowRoot=no

2、pkla:policy kit local authority的缩写,一个XML格式的本地授权文件,用于允许或拒绝用户执行特定的命令或操作。

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE pklocalauthority PUBLIC "-//freedesktop//DTD pklocalauthority//EN" "http://www.freedesktop.org/software/polkit/pklocalauthority.dtd">

<pklocalauthority>
  <!-- Let unprivileged users reboot and shut down the system. -->
  <action id="org.freedesktop.consolekit.system.restart-allow-more">
    <description>Restart allowed for everyone and multiple logind instances</description>
    <message>Authentication is required to restart the system</message>
    <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.consolekit.system.restart-multiple-sessions" type="BOOL" value="true">Whether to allow restarting when multiple sessions are active</annotate>
  </action>
</pklocalauthority>

3、policykit-default-privs:用于为所有系统提供通用行为的本地授权文件。

org.freedesktop.hal.detach-encrypted.partitions
org.freedesktop.hal.power-management.hibernate
org.freedesktop.hal.power-management.reboot
org.freedesktop.hal.power-management.shutdown
org.freedesktop.hal.power-management.suspend
org.freedesktop.hal.power-management.suspend-hybrid

原创文章,作者:ZELDI,如若转载,请注明出处:https://www.506064.com/n/330103.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
ZELDI的头像ZELDI
上一篇 2025-01-14 18:56
下一篇 2025-01-14 18:56

相关推荐

  • 神经网络代码详解

    神经网络作为一种人工智能技术,被广泛应用于语音识别、图像识别、自然语言处理等领域。而神经网络的模型编写,离不开代码。本文将从多个方面详细阐述神经网络模型编写的代码技术。 一、神经网…

    编程 2025-04-25
  • Linux sync详解

    一、sync概述 sync是Linux中一个非常重要的命令,它可以将文件系统缓存中的内容,强制写入磁盘中。在执行sync之前,所有的文件系统更新将不会立即写入磁盘,而是先缓存在内存…

    编程 2025-04-25
  • Python输入输出详解

    一、文件读写 Python中文件的读写操作是必不可少的基本技能之一。读写文件分别使用open()函数中的’r’和’w’参数,读取文件…

    编程 2025-04-25
  • nginx与apache应用开发详解

    一、概述 nginx和apache都是常见的web服务器。nginx是一个高性能的反向代理web服务器,将负载均衡和缓存集成在了一起,可以动静分离。apache是一个可扩展的web…

    编程 2025-04-25
  • Java BigDecimal 精度详解

    一、基础概念 Java BigDecimal 是一个用于高精度计算的类。普通的 double 或 float 类型只能精确表示有限的数字,而对于需要高精度计算的场景,BigDeci…

    编程 2025-04-25
  • Python安装OS库详解

    一、OS简介 OS库是Python标准库的一部分,它提供了跨平台的操作系统功能,使得Python可以进行文件操作、进程管理、环境变量读取等系统级操作。 OS库中包含了大量的文件和目…

    编程 2025-04-25
  • MPU6050工作原理详解

    一、什么是MPU6050 MPU6050是一种六轴惯性传感器,能够同时测量加速度和角速度。它由三个传感器组成:一个三轴加速度计和一个三轴陀螺仪。这个组合提供了非常精细的姿态解算,其…

    编程 2025-04-25
  • Linux修改文件名命令详解

    在Linux系统中,修改文件名是一个很常见的操作。Linux提供了多种方式来修改文件名,这篇文章将介绍Linux修改文件名的详细操作。 一、mv命令 mv命令是Linux下的常用命…

    编程 2025-04-25
  • git config user.name的详解

    一、为什么要使用git config user.name? git是一个非常流行的分布式版本控制系统,很多程序员都会用到它。在使用git commit提交代码时,需要记录commi…

    编程 2025-04-25
  • 详解eclipse设置

    一、安装与基础设置 1、下载eclipse并进行安装。 2、打开eclipse,选择对应的工作空间路径。 File -> Switch Workspace -> [选择…

    编程 2025-04-25

发表回复

登录后才能评论