เหตุใด pkexec จึงนิยมใช้มากกว่า gksudo สำหรับแอปพลิเคชันกราฟิก


10

โปรดระบุเอกสาร 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

สำหรับ 13.04+ เหตุผลหนึ่งที่สำคัญคือ gksu ที่ไม่ได้อยู่ในการโหลดการเริ่มต้น
Oli

pkexec ไม่ใช่การแทนที่สำหรับ gksu มันไม่ได้มีไว้สำหรับคุณที่จะทำงานด้วยตนเอง
psusi

2
ฉันไม่ได้ถามหรือพูดถึง gksu
chili555

คำตอบที่ดีมากเกี่ยวกับการpkexecเรียกใช้ GUI โดยไม่ต้องกำหนดค่า: askubuntu.com/a/332847/89385
akostadinov

ติดตั้ง policykit-1-gnome ดูที่นี่สำหรับรายละเอียดและคำอธิบาย
user303371

คำตอบ:


7

ทำไมมันไม่ทำงาน

โดยค่าเริ่มต้น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.

ตามที่ระบุไว้ใน man page คุณสามารถทำให้มันใช้งานได้แม้ว่าฉันจะไม่รู้ว่าสิ่งนี้เป็นอันตรายหรือแนะนำก็ตาม

หากต้องการเปิดใช้งาน gedit คุณสามารถสร้าง/usr/share/polkit-1/actions/com.ubuntu.gedit.policyด้วยเนื้อหาต่อไปนี้:

<?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.0/policyconfig.dtd">
<policyconfig>
  <vendor>gedit</vendor>
  <vendor_url>gedit</vendor_url>
  <icon_name>accessories-text-editor</icon_name>
  <action id="org.freedesktop.policykit.pkexec.gedit">
   <description>Run "gedit"</description>
   <message>Authentication is required to run Text Editor</message>
   <defaults>
     <allow_any>auth_admin</allow_any>
     <allow_inactive>auth_admin</allow_inactive>
     <allow_active>auth_admin</allow_active>
   </defaults>
     <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/gedit</annotate>
     <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
   </action>  
</policyconfig>

จากนั้นpkexec geditควรทำงานตามที่คาดไว้:

ป้อนคำอธิบายรูปภาพที่นี่

ในขณะที่คุณสามารถคาดเดาสิ่งนี้จะgeditทำงานได้ ในทางทฤษฎีหากคุณเพิ่มallow_guiใน "org.freedesktop.policykit.exec" (การกระทำเริ่มต้น) สิ่งนี้ควรใช้กับแอปพลิเคชันทั้งหมด แต่ในการทดสอบของฉันฉันได้รับผลลัพธ์เช่นเดียวกับคุณ

ทำไม pkexec ถึงเลือก?

ที่นี่pkexecคุณสามารถหาการอภิปรายเกี่ยวกับจุดแข็งของการเป็น


3
ดังนั้นสำหรับแอปพลิเคชันกราฟิก gksudo เป็นที่ต้องการและไม่ใช่ pkexec?
chili555

1
ฉันเดาอย่างนั้น หากgksudoพร้อมใช้งานจะเป็นการง่ายกว่าที่จะใช้แทนที่จะสร้างการกระทำเดียวสำหรับแต่ละแอพที่คุณต้องการใช้ (หากไม่มีวิธี "ทั่วโลก" ในการทำ)
เซเลม

1
@ Salem- แล้วฉันสงสัยว่าทำไมคำตอบของฉันได้รับการแก้ไขและอนุมัติให้ใช้ pkexec เมื่อไม่ได้ตั้งใจจะใช้สำหรับแอปพลิเคชันแบบกราฟิกและอย่างที่คุณสามารถอ่านได้ไม่ทำงาน askubuntu.com/questions/313619/…ต้องมีบางอย่างที่ฉันไม่เข้าใจ
chili555

@ chili555 หากการแก้ไขนั้นเป็นสิ่งที่กระตุ้นคำถามของคุณคุณควรถามคำถามนี้ที่ Meta ใน 13.04 คุณต้องติดตั้งgksudoหรือกำหนดค่าpkexec(คุณสามารถใช้งานได้sudo -iแต่จะไม่ทำงานกับ Alt + F2 aka "Run") ฉันพบว่าครั้งแรกมากขึ้น ถ้าใครคิดอย่างอื่นดี ... ให้ฉันดูเหมือนว่าผิดที่จะแนะนำสิ่งที่จะไม่ทำงานตามที่ตั้งใจไว้ แต่ผมอาจจะหายไปบางสิ่งบางอย่าง ...
ซาเลม

1
pkexecจริง ๆ แล้วสามารถเรียกใช้ GUI ได้โดยไม่ต้องกำหนดค่า: askubuntu.com/a/332847/89385
akostadinov
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.