Skip to content

Instantly share code, notes, and snippets.

@paulgreg
Created February 26, 2020 21:07
Show Gist options
  • Save paulgreg/9fd6639a74e8e1e565022ffc02698ef5 to your computer and use it in GitHub Desktop.
Save paulgreg/9fd6639a74e8e1e565022ffc02698ef5 to your computer and use it in GitHub Desktop.
A simple oathtool wrapper to generate second factor TOTP token stored in a gpg encrypted file
#!/usr/bin/env bash
if [ -z $1 ]; then
echo
echo "Usage:"
echo " ./totp.sh service"
echo
echo "Configuration: $HOME/.totpkeys.gpg"
echo "File encoded with gpg"
echo "Format: service=key"
exit
fi
OTPKEY=$(gpg --decrypt $HOME/.totpkeys.gpg| sed -n "s/${1}=//p")
if [ -z "$OTPKEY" ]; then
echo "$(basename $0): Bad Service Name '$1'"
$0
exit
fi
TIME=$(date +"%T")
echo -n "Code for $1 at $TIME : "
oathtool --totp -b "$OTPKEY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment