Skip to content

Instantly share code, notes, and snippets.

@jtdressel
jtdressel / __description__ macOS - Fix for sudo command error: "unable to initialize PAM: No such file or directory" (Intel+M1)
In most cases, the `sudo` command error `unable to initialize PAM: No such file or directory` mostly appears when the pluggable authentication module file `/etc/pam.d/sudo` was edited with a typo or wrong pam module, etc.
## Via Single-User-Mode > Terminal
If you have an older Mac, you can boot into `single-user mode`, directly into the command line mode of macOS by skipping the UI:
* Press and hold down `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`.