# You can use Touch ID for sudo

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 shows up. You can set this up in about a minute.

![The Touch ID prompt for sudo, showing who asked and the command](https://modulovalue.com/assets/posts/touch-id-for-sudo/prompt.png)

## Turning it on

`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:

```
sudo cp /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local
sudo nano /etc/pam.d/sudo_local
```

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

```
auth       sufficient     pam_tid.so
```

`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.

## My version

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.

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](https://github.com/modulovalue/skills/tree/main/macos-touchid-sudo) in my [skills repository](https://github.com/modulovalue/skills).

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.

![My desk with three MacBooks, all of them using Touch ID for sudo](https://modulovalue.com/assets/posts/touch-id-for-sudo/setup.jpg)

## Addendum

[ryan-duve pointed out](https://lobste.rs/c/drnvap) 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:

```
# Replace last term with your target command.
agent_user  ALL = (ALL) NOPASSWD: /usr/bin/gdb
```

Commands you approved in advance then run silently, and Touch ID only shows 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.

[a1b3c3d7 mentioned](https://www.reddit.com/r/ClaudeCode/comments/1y93y8f/comment/19tetmr9zigsj/) 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.

[BaziBuilds pointed out](https://www.reddit.com/r/MacOS/comments/1y94vcs/comment/19tevdqtvhg02/) that inside tmux, the Touch ID prompt won't show up unless you also install [pam-reattach](https://github.com/fabianishere/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.

* * *

[Discuss on r/ClaudeCode](https://www.reddit.com/r/ClaudeCode/comments/1y93y8f/)

[Discuss on r/MacOS](https://www.reddit.com/r/MacOS/comments/1y94vcs/you_can_use_touch_id_for_sudo/)

[Discuss on Lobsters](https://lobste.rs/s/xsci5l/you_can_use_touch_id_for_sudo)

Subscribe to get new posts.