The approach I would take in this case, and as indicated here, is to boot into recovery mode (or "single user" mode), then fix the permissions on the /etc/sudoers file.

That answer is for Ubuntu, but the same approach should work regardless of distribution.

If you for some reason cannot boot into recovery mode, then I would suggest that you use a Live medium (CD, USB) and fix the permissions from there.

Answer from anon on Stack Exchange
🌐
GitHub
github.com › MiKTeX › miktex › issues › 1436
pkexec not found although installed (Linux, MiKTeX 23.12) · Issue #1436 · MiKTeX/miktex
January 25, 2024 - No graphical sudo frontend is available. Please install 'pkexec', 'kdesu' (KDE) or 'gksu' (Gnome).
Author   MiKTeX
Discussions

cannot use pkexec - Support - Whonix Forum
I have found a solution, but it only works in my friend’s (fresh) Whonix 15, and not mine. The easy test anyone can do is to do pkexec mousepad from Workstation Terminal. It SHOULD launch the pkexec prompt, as a simple test of its operation. It does in my friend’s, but it does not in mine. More on forums.whonix.org
🌐 forums.whonix.org
0
September 16, 2019
GUI not starting due to missing `pkexec` (Debian 12 KDE)
Apr 24 17:11:25 debian ... plasmashell[15208]: Creating dir "/tmp/input-remapper-watty" Apr 24 17:11:25 debian plasmashell[15213]: sh: 1: pkexec: not found Apr 24 17:11:25 debian plasmashell[15208]: ERROR: Failed to pkexec the reader-service, code 32512... More on github.com
🌐 github.com
4
April 24, 2024
v4l2 Virtual camera - Start Button logs: sh: 1: pkexec: not found
Attempted path: share/obs/obs-... error: v4l2-input: /dev/v4l/by-path/pci-0000:05:00.3-usb-0:2:1.0-video-index0: failed to log status sh: 1: pkexec: not found sh: 1: pkexec: not found sh: 1: pkexec: not found... More on github.com
🌐 github.com
6
October 6, 2021
python - pkexec "no such file or directory found" when trying to execute a binary from a script - Stack Overflow
I'm trying to execute a binary from a python script by using asyncio. I'm using the run command from here. I tried running it regularly, but I apparently don't have the permissions (even though it ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Snapcraft
forum.snapcraft.io › t › pkexec-not-found-python-gtk-gnome-app › 36579
Pkexec: not found (Python GTK/GNOME app) - snapcraft - snapcraft.io
August 28, 2023 - Hi, I’m trying to update Snap package for an existing Snap CLI app (auto-cpufreq), which is created using following snapcraft.yaml name: auto-cpufreq base: core22 summary: Automatic CPU speed & power optimizer for Linux description: | Automatic CPU speed & power optimizer for Linux based ...
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
[SOLVED] pkexec xed not working - Linux Mint Forums
I just tried it on a clean install of XFCE 20.0 and it also does not work. I strongly suspect this functionality has been removed, because most Linux distros view running GUI application as root as being a security risk. I can pkexec with thunar also, for now.
🌐
Whonix
forums.whonix.org › support
cannot use pkexec - Support - Whonix Forum
September 16, 2019 - I have found a solution, but it only works in my friend’s (fresh) Whonix 15, and not mine. The easy test anyone can do is to do pkexec mousepad from Workstation Terminal. It SHOULD launch the pkexec prompt, as a simple test of its operation. It does in my friend’s, but it does not in mine.
Top answer
1 of 3
58

How to configure pkexec to avoid getting errors when run GUI applications?

I found two possible ways:

  1. As you can see, using the following:

    pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit
    

    will not get you any error. And this is normal because man pkexec is very clear in this matter:

           [...] pkexec will not allow you to run X11 applications
           as another user since the $DISPLAY and $XAUTHORITY environment
           variables are not set.[...]
    

    As result you can create an (permanent) alias (this is the simpliest way):

    alias pkexec='pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY'
    
  2. Or, (again) as man pkexec says:

           [...] 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.[...]
    

    you can create a new policy file in /usr/share/polkit-1/actions named com.ubuntu.pkexec.gedit.policy with the following xml code inside where the most important thing is to set org.freedesktop.policykit.exec.allow_gui to a nonempty value:

    <?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/policyconfig.dtd">
    <policyconfig>
    
      <action id="com.ubuntu.pkexec.gedit">
        <message gettext-domain="gparted">Authentication is required to run gedit</message>
        <icon_name>gedit</icon_name>
        <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>
    

How to tell it to not ask for a password after the first time applying it to a command?

For these three setting tags: allow_any, allow_inactive and allow_active from the policy file, the following options are available:

  • no: The user is not authorized to carry out the action. There is therefore no need for authentication.
  • yes: The user is authorized to carry out the action without any authentication.
  • auth_self: Authentication is required but the user need not be an administrative user.
  • auth_admin: Authentication as an administrative user is require.
  • auth_self_keep: The same as auth_self but, like sudo, the authorization lasts a few minutes.
  • auth_admin_keep: The same as auth_admin but, like sudo, the authorization lasts a few minutes.

     Source: Polkit - Structure - Actions

So, if you use auth_admin_keep option (or, as applicable, auth_self_keep), pkexec will not ask for a password again for some time (by default this time is set to 5 minutes as I checked). The disadvantage here is that this thing is applicable only for one - the same - command / application and valid for all users (unless if it is overruled in later configuration).

Where to save the configuration file if not yet existing?

Configuration files or polkit definitions can be divided into two kinds:

  • Actions are defined in XML .policy files located in /usr/share/polkit-1/actions. Each action has a set of default permissions attached to it (e.g. you need to identify as an administrator to use the GParted action). The defaults can be overruled but editing the actions files is NOT the correct way. The name of this policy file should have this format:

    com.ubuntu.pkexec.app_name.policy
  • Authorization rules are defined in JavaScript .rules files. They are found in two places: 3rd party packages can use /usr/share/polkit-1/rules.d (though few if any do) and /etc/polkit-1/rules.d is for local configuration. The .rules files designate a subset of users, refer to one (or more) of the actions specified in the actions files and determine with what restrictions these actions can be taken by that/those user(s). As an example, a rules file could overrule the default requirement for all users to authenticate as an admin when using GParted, determining that some specific user doesn't need to. Or isn't allowed to use GParted at all.

     Source: Polkit - Structure

Is there a GUI application to configure pkexec usage?

From what I know, until now (18.01.2014) doesn't exist something like this. If in the future I will find something, I will not forget to update this answer too.

2 of 3
2

In addition to Radu's answer: I would not use the alias pkexec, but gksudo.

Why? You don't need to rewrite your script.

I use the following configuration:

  • open a terminal
  • cd /usr/local/bin
  • sudo gedit gksudo (create new file called "gksudo"
  • write the following content:

    • pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $@

    • (don't forget the $@ at the end. This is for redirecting all parameters)

  • save and quit

  • make the file executable: chmod 755 gksudo
  • Now you should have a fully functional gksudo command available on your system - permanently.

For documentation reasons, I will write, what I tried and didn't work out:

  • alias pkexec='pkexec env [...]'
  • alias gksudo='pkexec [...]'
    • Was not permanent and did only stay in one single terminal
  • adding the alias to ~/.bash_aliases
    • Works if you first open a terminal. Does not work, if you doubleclick scripts
  • Create a link to pkexec with parameters ( ln -s pkexec [...])
    • After a quick googleing, it seems like linux doesn't support parameters in links
🌐
CodeWeavers
support.codeweavers.com › missingpkexec
Missing pkexec tool - CodeWeavers
Description The pkexec tool may be needed to run commands as root. Resolution On CrossOver 17 and greater, the simplest solution to fix this issue is to ru
🌐
GitHub
github.com › sezanzeb › input-remapper › issues › 878
GUI not starting due to missing `pkexec` (Debian 12 KDE) · Issue #878 · sezanzeb/input-remapper
April 24, 2024 - Apr 24 17:11:25 debian plasmashell[15208]: input-remapper-gtk 2.0.1 f5151aab27ae0e7d8b1f0c80ce92a718e3a86e71 https://github.com/sezanzeb/input-remapper Apr 24 17:11:25 debian plasmashell[15208]: python-evdev 1.6.1 Apr 24 17:11:25 debian plasmashell[15208]: Creating dir "/tmp/input-remapper-watty" Apr 24 17:11:25 debian plasmashell[15213]: sh: 1: pkexec: not found Apr 24 17:11:25 debian plasmashell[15208]: ERROR: Failed to pkexec the reader-service, code 32512
Author   sezanzeb
Find elsewhere
🌐
GitHub
github.com › obsproject › obs-studio › issues › 5386
v4l2 Virtual camera - Start Button logs: sh: 1: pkexec: not found · Issue #5386 · obsproject/obs-studio
October 6, 2021 - Attempted path: share/obs/obs-... error: v4l2-input: /dev/v4l/by-path/pci-0000:05:00.3-usb-0:2:1.0-video-index0: failed to log status sh: 1: pkexec: not found sh: 1: pkexec: not found sh: 1: pkexec: not found...
Author   obsproject
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
pkexec doesn't show anything when upgrading to 22.1 - Linux Mint Forums
February 9, 2025 - In one of them when running any application that asks for sudo password in graphical window doesn't do anything. After searching I've found that the command "pkexec" is the responsible for that. If I open a terminal and run that command, then nothing happens, no error, no window asking for ...
🌐
Loginroot
pkgs.loginroot.com › errors › notFound › pkexec
pkexec: command not found
pkexec: kommandot finns inte pkexec: komut yok pkexec: nie znaleziono polecenia pkexec: níor aimsíodh an t-ordú pkexec: no se encontró la orden pkexec: no s'ha trobat l'ordre pkexec: opdracht niet gevonden pkexec: parancs nem található pkexec: perintah tidak ditemukan pkexec: príkaz nenájdený pkexec: příkaz nenalezen pkexec: команда не найдена pkexec: командата не е открита pkexec: 命令找不到 pkexec: コマンドが見つかりません · czmq_selftest: command not found db_load: command not found eject: command not found s390x-linux-gnu-cpp:
🌐
Linux Man Pages
linux.die.net › man › 1 › pkexec
pkexec(1): Execute command as another user - Linux man page
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 e.g.
🌐
Command Not Found
command-not-found.com › pkexec
command-not-found.com – pkexec
Install pkexec command on any operating system and in Docker.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
[SOLVED] Running pkexec in terminal works but not in Alt-F2 - Linux Mint Forums
December 10, 2018 - I probably post this under a new ... XAUTHORITY=$XAUTHORITY HOME=$HOME "$@"' > ~/.local/bin/gksudo chmod u+x ~/.local/bin/gksudo Reload Cinnamon or relog, then you can prefix that instead of pkexec....
🌐
Ubuntu Manpages
manpages.ubuntu.com › focal › man(1)
Ubuntu Manpage: pkexec - Execute a command as another user
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.
🌐
GitHub
github.com › microsoft › vscode › issues › 109808
Cannot save as root: unable to find pkexec · Issue #109808 · microsoft/vscode
November 1, 2020 - Error pops up: Failed to save '...': Unable to find pkexec or kdesudo.
Author   microsoft