Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bulletinmybeard/fa17ad819e23f3d8629aa723982d4703 to your computer and use it in GitHub Desktop.
Save bulletinmybeard/fa17ad819e23f3d8629aa723982d4703 to your computer and use it in GitHub Desktop.
macOS - Fix for sudo command error: "unable to initialize PAM: No such file or directory" (Intel+M1)

In most cases, the sudo command displays the error unable to initialize PAM: No such file or directory mostly appears when the pluggable authentication module file /etc/pam.d/sudo has been edited with a typo or an incorrect PAM module.

Via Single-User-Mode > Terminal

If you have an older Mac, you can boot into single-user mode, which allows you to access the command line mode of macOS directly, bypassing the UI.

  • Press and hold down the COMMAND + S keys until you see commands being executed in the Terminal.

  • Open the sudo file with vi /Volumes/Macintosh\ - Data/etc/pam.d/, fix what's wrong, save and close the file by switching from INSERT to the COMMAND mode with the ESC key, type :wq!, and hit enter.

  • Close the Terminal via the menu from the top of the screen

  • Restart your machine

  • Back into the UI, open your Terminal, and verify the file content fix with cat /etc/pam.d/sudo. If everything looks good, give it a try by running: sudo whoami.

Via Recovery Mode > Terminal

On modern M1 Silicon machines, there is no single-user mode available, which is why the following steps differ here.

  • Boot into recovery mode by pressing and holding the power button on your Mac until you see Loading startup options.

  • Click on Options, and then click on Continue.

  • If requested, enter the password for an administrator account. This will take you to the macOS Utilities screen.

  • Go to "Disk Utility" and check if "Macintosh - Data" is mounted; if not, mount it by clicking the "Mount" button in the top right corner.

  • Close "Disk Utility" and return to "macOS Utilities".

  • Access the Terminal by selecting it from the menu at the top of the screen and launch the Terminal.

  • Open the sudo file with vi /Volumes/Macintosh\ - Data/etc/pam.d/, correct any errors, save and close the file by switching from INSERT to the COMMAND mode using the ESC key, typing :wq!, and pressing enter.

  • Close the Terminal using the menu at the top of the screen

  • Restart your machine

  • Go back to the UI, open your Terminal, and verify the file content fix with cat /etc/pam.d/sudo. If everything looks good, give it a try by running: sudo whoami.

Cheers \w

@testpassword
Copy link

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment