Use Touch ID for sudo on Mac

By  on  

The landscape of security is changing quite a bit. We've gone from basic username and password to 2FA, facial recognition, fingerprint recognition, and so on. Hell, my Mac unlocks simply when I have my Apple Watch near by. In the end, I probably use the Mac fingerprint key the most.

One functionality that still requires manually typing a password is using sudo from command line. Did you know, however, that you can instead require the fingerprint key instead of typing out your password?

# Open the sudo utility
sudo vi /etc/pam.d/sudo

# Add the following as the first line
auth sufficient pam_tid.so

Whether or not you'd prefer to type it out or simply use the fingerprint is obviously personal preference. Since you expect to be be typing in a command line, moving your finger to touch the key is probably not very efficient. If you do want to use fingerprint, however, here you go!

Recent Features

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

Incredible Demos

  • By
    Translate Content with the Google Translate API and JavaScript

    Note:  For this tutorial, I'm using version1 of the Google Translate API.  A newer REST-based version is available. In an ideal world, all websites would have a feature that allowed the user to translate a website into their native language (or even more ideally, translation would be...

  • By
    Dynamically Load Stylesheets Using MooTools 1.2

    Theming has become a big part of the Web 2.0 revolution. Luckily, so too has a higher regard for semantics and CSS standards. If you build your pages using good XHTML code, changing a CSS file can make your website look completely different.

Discussion

  1. Luka

    First you need to make the file writable (it is not by default). And you need to do this after every macOS update, because macOS updates reset the file content.

  2. Yohann Paris

    Nice trick. Unfortunately, on Big Sur, at least, it pops up the touch id alert to use it only when the session is terminated, so it’s not useful.

  3. Mehdi Abbassi

    But it is read-only!

  4. Robert Coggeshall

    As the co-author of sudo, I am amused :)

  5. No need to make it writable when editing it with vi, you just add a ! to the save and exit command (:wq!) and it will save it corectly – it will even preserve the read only state of the file.

    Works nicely on Big Sur for me, it pops up the touch id alert, I touch and sudo all the things =)

  6. Is there a way to make sudo work with the Apple Watch as well?

  7. You can also:
    *browse to the folder using finder,
    *edit the file with vscode, or any other code editor
    *save it to desktop
    *delete original file
    *and place the edited

  8. same with nano you don’t need to make it writable.

    sudo nano /etc/pam.d/sudo
    
  9. Thomas B

    You may want to update this for Sonoma – or simple add a pointer to https://0xmachos.com/2023-10-01-Touch-ID-sudo/

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!