Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active March 15, 2023 08:00
Show Gist options
  • Save ruario/d10fc1515149e77742838b3bb6ba3a74 to your computer and use it in GitHub Desktop.
Save ruario/d10fc1515149e77742838b3bb6ba3a74 to your computer and use it in GitHub Desktop.
This is a short script to display TOTP codes using MinTOTP, with code seeds encrypted with GPG
#!/usr/bin/env bash
# This is a short script to display TOTP codes using MinTOTP
# <https://github.com/susam/mintotp>
#
# You will need to add your secret keys into an encrypted file (called
# '~/.totp-seeds.dat') formatted like so:
#
# amazon:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# github:YYY YYY YYY YYY YYYY
# paypal:ZZZZZZZZZZZZZZZZ
#
# Note: These are memorable (self-selected) keywords, followed by a ':' and
# then the relevant code/secret key/seed that sites provided to you as an
# alternative to QR code scanning.
#
# You can create this file with the following command:
#
# gpg2 --symmetric --cipher-algo AES256 --output "$HOME/.totp-seeds.dat"
#
# It is then necessary to enter and confirm your preffered passphrase,
# followed by the lines and ended with 'Ctrl+d'.
#
# You can view the list and check it is correct with:
#
# gpg2 --decrypt --quiet "$HOME/.totp-seeds.dat"
#
# There should be no extraneous lines that do not match the above suggested
# formatting.
#
# Once done you can run this script to print out the current one time
# passwords for each site.
names_totp="$(mktemp -t names-totp.XXXXXX)"
numbers_totp="$(mktemp -t numbers-totp.XXXXXX)"
gpg2 --decrypt --quiet "$HOME/.totp-seeds.dat" | tee >(cut -d: -f1 > "$names_totp") | cut -d: -f2 | tr -d ' ' | mintotp > "$numbers_totp"
paste -d' ' "$numbers_totp" "$names_totp"
rm "$numbers_totp" "$names_totp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment