How to sudo when sudo stopped working on Ubuntu Desktop

Wed Sep 20 2023 00:00:00 GMT+0000 (Coordinated Universal Time)

Got into a situation on a Ubuntu desktop Linux where the sudo configuration files had the wrong ownership and I could not change it back because, I had no sudo anymore. Turns out there is another way on Ubuntu Desktop (at least) to execute commands with elevated privileges: pkexec.

Just prefix in the CLI with pkexec what it is you want to do and you'll get a GUI dialog to enter your password.

It uses a different authorization system than sudo it seems, from its man page:

"By default, the org.freedesktop.policykit.exec authorization is required unless an action definition file is present for the program in question. To require another authorization, it can be specified using the org.freedesktop.policykit.exec.path annotation on an action (See the section called “EXAMPLE” for details)."