Touch ID for Terminal sudo#
Enable this and sudo prompts for your fingerprint instead of your admin password. It works in Terminal, iTerm2, VS Code, and any other terminal on the machine.
Requirements:
- A Mac with a Touch ID sensor, or a Magic Keyboard with Touch ID.
- An admin account.
Read this before you edit anything#
A syntax error in a PAM file can lock you out of sudo completely. There is no undo prompt. Protect yourself:
- Open a second terminal window and run
sudo -vin it before you start. Leave that window open. It holds an authenticatedsudosession you can use to repair the file. - Only add the exact line shown below. Do not delete or reorder existing lines.
Method 1 — macOS 14 Sonoma and later (recommended)#
macOS 14 added /etc/pam.d/sudo_local. macOS updates do not overwrite this file, so the setting survives upgrades.
- Copy Apple's template into place.
sudo cp /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local
-
Enter your account password when prompted.
-
Open the copy in
nano.
sudo nano /etc/pam.d/sudo_local
- Find this line and delete the leading
#and the space after it.
#auth sufficient pam_tid.so
The result must read:
auth sufficient pam_tid.so
-
Save with Control + O, then press Enter to confirm the filename.
-
Exit with Control + X.
-
Test it. A Touch ID prompt appears instead of a password prompt.
sudo ls
Method 2 — macOS 13 Ventura and earlier#
Older macOS has no sudo_local. Edit /etc/pam.d/sudo directly.
A macOS update can overwrite /etc/pam.d/sudo and remove your change. Re-apply these steps after any major system update.
- Open the file.
sudo nano /etc/pam.d/sudo
-
Enter your account password when prompted.
-
Move the cursor to the line directly below the
#%PAM-1.0comment at the top. -
Add this line. It must sit above every other
authline.
auth sufficient pam_tid.so
-
Save with Control + O, press Enter, then exit with Control + X.
-
Test with
sudo ls.
Why the order matters#
PAM reads auth rules top to bottom. sufficient means "if this rule passes, stop and allow". If pam_tid.so sits below pam_opendirectory.so, the password check runs first and Touch ID never gets a turn. Put it first.
Troubleshooting#
- No prompt inside
tmuxorscreen. These detach the process from the GUI session, so the Touch ID dialog cannot appear. Installpam_reattachand add it above thepam_tid.soline.
brew install pam-reattach
Then add this line immediately before pam_tid.so:
auth optional /opt/homebrew/lib/pam/pam_reattach.so
- Apple Watch does not work. Unlock-with-Apple-Watch does not substitute for Touch ID at a
sudoprompt. You must use the sensor. - Nothing changed. Confirm the file has no leading
#on the line, and that the line is above the otherauthentries. Then open a new terminal window — the change applies to newsudoinvocations. - You are locked out of
sudo. Use the second terminal window from the warning above to restore the file. If you did not open one, boot into Recovery Mode and repair/etc/pam.d/sudofrom there.