Forked from bulletinmybeard/fix-for-sudo-command-error-unable-to-initialize-pam-no-such-file-or-directory.md
Created
April 29, 2022 03:59
-
-
Save jtdressel/e53fd36c053c77abc76a737ef13a2cbc 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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | |
## Via Recovery Mode > Terminal | |
On modern `M1 Silicon` machines, there's no `single-user mode` available, 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 Options, then click 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 the "Macintosh - Data" is mounted; otherwise, mount it by pressing the "mount" button on the top right corner. | |
* Close "Disk Utility" and get back to "macOS Utilities". | |
* Access the Terminal via the menu from the top of the screen and launch 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`. | |
Cheers \w |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment