Skip to content

Instantly share code, notes, and snippets.

@dzerrenner
Created January 11, 2021 17:01
Show Gist options
  • Save dzerrenner/0e68c36cff119560f1829001e649bec5 to your computer and use it in GitHub Desktop.
Save dzerrenner/0e68c36cff119560f1829001e649bec5 to your computer and use it in GitHub Desktop.
How to restore a fatfingered sudoers file

I recently fatfingered my sudoers file on a Ubuntu 20.04 machine. All commands involving sudo failed with a core dump. Here's how I got it back:

I found a tip somewhere on stackoverflow: use pkexec. This utilizes Policykit (http://manpages.ubuntu.com/manpages/focal/man8/polkit.8.html). In short: pkexec can run programs as root. In my case I had also to use pkttyagent to provide an authorization context. This works as follows (got it from: https://askubuntu.com/a/1053617)

  1. Open 2 termianl windows / ssh sessions.
  2. Get the PID of the shell process from the first one (echo $$)
  3. Execute this in the second terminal: pkttyagent --process (pid from step 2)
  4. Back to the first session, issue pkexec viduso
  5. Enter the password in the second session.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment