Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

pkexec

Run a program as another user (by default root) when polkit allows it.

Niveau
Extra
Groep
Gebruikers en groepen
Root nodig
Voor wijzigingen
Pakket
polkit

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

pkexec is the polkit way to run a command with more rights. polkit checks the rules for the action org.freedesktop.policykit.exec; normally an administrator (on RHEL: member of wheel) must type the own password.

Most admins use sudo. pkexec is used by desktop tools and when sudo is not set up. polkit also controls actions of system services (network, power, disks) — systemctl or nmcli ask polkit when you are not root.

Zo schrijf je het

pkexec [--user USER] PROGRAM [ARGUMENTS]...
pkexec --disable-internal-agent PROGRAM
pkexec --version | --help

Opties 5

Meest gebruikt

--user USER
Run the program as this user (default root).
--keep-cwd
Keep the current folder (newer versions).
--disable-internal-agent
Do not use the text agent to ask the password.
--help
Show help.
--version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Run a command as root

    pkexec systemctl restart chronyd

    polkit asks the password of an admin user.

  2. 2Run as another user

    pkexec --user apache whoami

    polkit decides if you may.

  3. 3See what polkit allows you in NetworkManager

    nmcli general permissions

    yes / auth / no per action.

  4. 4List all polkit actions

    pkaction | head

    Every action a service checks with polkit.

  5. 5Show details of one action

    pkaction --verbose --action-id org.freedesktop.policykit.exec

    Shows who may do it (implicit any/inactive/active).

  6. 6Check one action for your session

    pkcheck --action-id org.freedesktop.NetworkManager.network-control --process $$ -u

    Tests the rule without doing the action.

  7. 7Find the rule that makes wheel admin

    grep -r wheel /usr/share/polkit-1/rules.d/

    polkit.addAdminRule returns unix-group:wheel.

  8. 8Restart a service as a normal user

    systemctl restart httpd

    Without sudo, systemctl asks polkit, which asks an admin password.

  9. 9Check that the polkit service runs

    systemctl status polkit

    Without it, polkit checks fail.

  10. 10Check the version after a security fix (PwnKit)

    rpm -q polkit

    CVE-2021-4034 (PwnKit) was a root hole in old pkexec versions; keep polkit updated.

Let op

  • pkexec is setuid root. Keep polkit updated.
  • Own rules go in /etc/polkit-1/rules.d/, not in /usr/share/polkit-1/.

Bestanden

/usr/share/polkit-1/actions/
Actions of the services.
/usr/share/polkit-1/rules.d/
Rules from packages.
/etc/polkit-1/rules.d/
Your own rules.

Exitcodes

0The program ran (or its exit code).
126Not authorized, or the dialog was closed.
127polkit not available or the program was not found.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man pkexec