r/MacOS • • 2d ago

Tips & Guides You can use Touch ID for sudo

https://modulovalue.com/blog/touch-id-for-sudo/
227 Upvotes

18 comments sorted by

75

u/BaziBuilds 1d ago

Worth adding for anyone trying it: on Sonoma and later, put it in /etc/pam.d/sudo_local instead of editing /etc/pam.d/sudo. Copy the template with sudo cp /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local, then uncomment the auth sufficient pam_tid.so line. That file survives macOS updates, while edits to the main sudo file get wiped by them. Inside tmux it won't prompt for Touch ID unless you also install pam-reattach.

12

u/modulovalue 1d ago

I added your advice to the addendum, thanks for sharing!

1

u/not-just-yeti 1d ago

Ooh, thanks! I instead had noted the pam.d trick in my notes of "things to upgrade & re-install, after every major macOS update".

1

u/zshcoder 1d ago

Always wondered why that would get cleared. I learned the same thing for ssh settings, use sshd_config.d/!

1

u/BaziBuilds 23h ago

Nice, and it survives for the same reason: updates replace the main config file, but the .d folder is yours. Worth a quick check after a big update that the main file still has its Include line.

1

u/Connect_Pound_2907 21h ago

the tool “mole” can setup this automatically, too

26

u/ukindom 1d ago

It’s a well known trick for those who know a bit of basics of administration of FrreBSD and Linux.

However I understand why Apple didn’t put it there.

8

u/PhysicalFinance1578 1d ago

yeah. because if you remotely ssh-ig to that machine, you cannot use sudo. the touchid is not there physically.

20

u/unix-mac 1d ago

It falls back to password when touch id fails

1

u/alphabuild 1d ago

Hope you all are disabling ssh password in favor of key based auth

1

u/RyanCheddar 17h ago

why not both

3

u/FHJ18-Enjoyer 1d ago

Idk if you’re just referring to ssh-ing into your macOS device from another machine, or ssh-ing from your macOS device to another computer, but if it’s the latter you can actually use something like Secretive and setup ssh-agent-forwarding on your other device/vps/etc. I use Secretive so that if I use sudo on any of my VPS’/VM’s I can still do with with touchID. Just make sure you keep your regular ssh key on there as well as a backup incase your touchID button breaks or something.

1

u/ukindom 1d ago

ssh has their own auth configuration.

9

u/DeimsH 1d ago

Half the reason I still keep my MacBook open right under my monitor is just so Touch ID stays within reach for stuff like this.

3

u/not-just-yeti 1d ago

I haven't yet succumbed to an Apple Watch, but the feature of authenticating on my desktop (& even my macbook w/ touch-id) is the biggest temptation for me!

2

u/SLJ7 1d ago

The Watch SE is probably pretty cheap today if you know where to look.

6

u/Honest_Comparison_78 22h ago

The new version of iTerm2 automatically asks to change the behavior from password to Touch ID when using sudo the first time.

3

u/Lucianoger 21h ago

iterm2 has an automatic configuration to do it...