詳解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/zh-hant/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

發表回復

登錄後才能評論