What it does
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.
How to write it
pkexec [--user USER] PROGRAM [ARGUMENTS]...
pkexec --disable-internal-agent PROGRAM
pkexec --version | --helpOptions 5
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Run a command as root
pkexec systemctl restart chronydpolkit asks the password of an admin user.
2Run as another user
pkexec --user apache whoamipolkit decides if you may.
3See what polkit allows you in NetworkManager
nmcli general permissionsyes / auth / no per action.
4List all polkit actions
pkaction | headEvery action a service checks with polkit.
5Show details of one action
pkaction --verbose --action-id org.freedesktop.policykit.execShows who may do it (implicit any/inactive/active).
6Check one action for your session
pkcheck --action-id org.freedesktop.NetworkManager.network-control --process $$ -uTests the rule without doing the action.
7Find the rule that makes wheel admin
grep -r wheel /usr/share/polkit-1/rules.d/polkit.addAdminRulereturns unix-group:wheel.8Restart a service as a normal user
systemctl restart httpdWithout sudo, systemctl asks polkit, which asks an admin password.
9Check that the polkit service runs
systemctl status polkitWithout it, polkit checks fail.
10Check the version after a security fix (PwnKit)
rpm -q polkitCVE-2021-4034 (PwnKit) was a root hole in old pkexec versions; keep polkit updated.
Nothing matches this filter.
Watch out
- pkexec is setuid root. Keep polkit updated.
- Own rules go in /etc/polkit-1/rules.d/, not in /usr/share/polkit-1/.
Files
/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.
Exit codes
0 | The program ran (or its exit code). |
126 | Not authorized, or the dialog was closed. |
127 | polkit not available or the program was not found. |