Skip to content

Instantly share code, notes, and snippets.

@hrkt
Last active January 19, 2022 07:28
Show Gist options
  • Save hrkt/1bbac50c84d99fdb07375d713587f864 to your computer and use it in GitHub Desktop.
Save hrkt/1bbac50c84d99fdb07375d713587f864 to your computer and use it in GitHub Desktop.
A shell script to enable sudo by "Touch ID" on macOS
#!/bin/sh
# A shell script to enable sudo by "Touch ID" on macOS
# tested on macOS 11.6 Big Sur
TARGET_FILE=/etc/pam.d/sudo
# skip if it is not run on macOS
if [ 'Darwin' != `uname` ]; then
echo "not on macOS platform. exit."
exit 0
fi
# check target file
grep "auth sufficient pam_tid.so" $TARGET_FILE > /dev/null
if [ $? -ne 1 ]; then
echo "already has pam_tid.so line in ${TARGET_FILE}. do nothing."
exit 0
fi
# edit file with sed command.
# with -i option, sed creates backup file on the same directory.
sudo chmod +w ${TARGET_FILE}
sudo sed -i '.bak' -e '2 i\
auth sufficient pam_tid.so' ${TARGET_FILE}
if [ $? -ne 0 ]; then
echo "an error occured. exit."
exit 0
fi
sudo chmod -w ${TARGET_FILE}
echo "succeeds. see ${TARGET_FILE}."
cat ${TARGET_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment