Skip to content

Instantly share code, notes, and snippets.

@lgw4
Last active May 17, 2022 21:23
Show Gist options
  • Save lgw4/7592f1d1fab87033834c43e580fc758f to your computer and use it in GitHub Desktop.
Save lgw4/7592f1d1fab87033834c43e580fc758f to your computer and use it in GitHub Desktop.
Enable Touch ID on macOS terminal applications
#!/usr/bin/env sh
PAM_SUDO_FILE="/private/etc/pam.d/sudo"
PAM_TID="auth sufficient pam_tid.so"
if [ "$(uname)" != "Darwin" ]; then
echo "[ERROR]: Not on macOS. Exiting..."
exit 1
fi
grep -F "${PAM_TID}" ${PAM_SUDO_FILE} >/dev/null
if [ ${?} -ne 1 ]; then
echo "[WARNING]: ${PAM_SUDO_FILE} already contains pam_tid.so entry. Exiting..."
exit 1
fi
sudo chmod 644 ${PAM_SUDO_FILE}
sudo sed -i '.bak' "1a\\
${PAM_TID}
" "${PAM_SUDO_FILE}"
if [ ${?} -ne 0 ]; then
echo "[ERROR]: Unable to add pam_tid.so entry to ${PAM_SUDO_FILE}. Exiting..."
exit 1
fi
sudo chmod 444 ${PAM_SUDO_FILE}
echo "[SUCCESS]: pam_tid.so entry added to ${PAM_SUDO_FILE}."
printf "\n"
cat ${PAM_SUDO_FILE}
printf "\n"
if [ -d '/Applications/iTerm.app' ] || [ -d "${HOME}/Applications/iTerm.app" ]; then
echo "Checking iTerm.app Touch ID support configuration..."
PREFERENCE=$(defaults read com.googlecode.iterm2 BootstrapDaemon 2>/dev/null)
if [ "${PREFERENCE}" = "0" ]; then
echo "[SUCCESS]: iTerm.app is already configured properly to support Touch ID."
else
echo "[WARNING]: Setting iTerm.app preferences via 'defaults write' may not work while iTerm.app is running."
echo "[WARNING]: Be sure to disable this setting in iTerm's Preferences to enable Touch ID:"
echo " Preferences » Advanced » 'Allow sessions to survive logging out and back in'"
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment