Skip to content

Instantly share code, notes, and snippets.

@speto
Last active January 26, 2022 19:38
Show Gist options
  • Save speto/84263183e9d8d17343afcad217269ea7 to your computer and use it in GitHub Desktop.
Save speto/84263183e9d8d17343afcad217269ea7 to your computer and use it in GitHub Desktop.
Activate/Deactivate Touch ID for sudo in Terminal

Activate/Deactivate Touch ID for sudo in Terminal

Usage

zsh -c "$(curl -sL https://gist.githubusercontent.com/speto/84263183e9d8d17343afcad217269ea7/raw/touch_id_sudo.sh)"

Resources

#!/usr/bin/env zsh
case $(grep --silent "pam_tid.so" /etc/pam.d/sudo; echo $?) in
0)
echo "TouchID unlock already in place"
read "answer?Remove TouchID unlock (y/n)?"
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo sed -i '' '/pam_tid\.so/d' /etc/pam.d/sudo
if [ $? -eq 0 ]; then
echo "TouchID unlock removed"
exit 0
else
echo "Error trying to remove pam_tid.so from /etc/pam.d/sudo"
exit 1
fi
exit 0
fi
;;
1)
sudo sed -i '' '1a\
auth sufficient pam_tid.so
' /etc/pam.d/sudo
echo "TouchID unlock enabled"
exit 0
;;
*)
echo $?
echo "Error trying to read /etc/pam.d/sudo"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment