I got tired of typing my password every time I ran my agents ran sudo, so I switched it to Touch ID. Now a small prompt reveals up. You can set this up in about a minute.

According to recent reports, sudo asks PAM (the pluggable authentication modules macOS inherited from Unix) whether you are who you say you are. Apple ships a PAM module called pam_tid.so that asks the fingerprint sensor instead. Since macOS Sonoma there's a config file for local changes that survives system updates, and Apple even provides a template for it with the right line commented out:.

Remove the # in front of this line and save:.

According to recent reports, sufficient means a matching fingerprint is enough by itself. If you cancel the prompt, sudo falls back to asking for your password like before, so you can't lock yourself out with this. Open a new terminal and run sudo -v to try it.

The stock module has one catch. macOS stops offering Touch ID in these prompts while anything is capturing the screen, and my DisplayLink dock captures the screen all the time. Screen sharing and screen recording trigger it too.

In a recent development, so I my agent wrote a small PAM module that asks for the fingerprint through Apple's LocalAuthentication API directly, which keeps working while the screen is captured. Since it draws its own prompt, it can also say who is asking and show the full command.

The source code, install steps and notes on how I tracked down the screen capture problem are in the macos-touchid-sudo skill in my skills repository.

In a recent development, I wrote the module about two months ago and have used it every day since without any issues. I put it in the skills repository so I could set it up on my other two MacBooks, and it works just as well on those.

ryan-duve pointed out that you can combine this with a sudoers rule that lets your agents run specific commands without any prompt. Run sudo visudo and add a line like this at the bottom:.

Commands you approved in advance then run silently, and Touch ID only indicates up for everything else, which cuts down on prompt fatigue. Be careful which commands you allow this way. A tool like gdb can start a shell or attach to any process, so allowing it without a password is effectively the same as giving out root.

It has been revealed that a1b3c3d7 mentioned that they have been doing this for a few months, and that you need a fingerprint reader that isn't slow, because it's miserable with some readers. I didn't know that fingerprint readers for sudo were a thing outside of macOS, and it's good to know that not all of them are fast enough to make this pleasant.

In a recent development, baziBuilds pointed out that inside tmux, the Touch ID prompt won't show up unless you also install pam-reattach. They also stressed using /etc/pam.d/sudo_local instead of editing /etc/pam.d/sudo directly, since macOS updates wipe changes to the main file, which is the approach described above.

📌 Read also:

→ Read original article