Skip to content

Instantly share code, notes, and snippets.

@timmc
Created December 27, 2019 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/8e059a499dc1d7cc6c4b0dc5402a8fb1 to your computer and use it in GitHub Desktop.
Save timmc/8e059a499dc1d7cc6c4b0dc5402a8fb1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Generates a TOTP code and copies it to the clipboard.
# Accepts path to a GPG-encrypted TOTP secret key file.
# Usage: $0 <encrypted-secrets-file>
#
# Encrypt a secret like this: xsel -bo | gpg2 --encrypt --recipient 0x32D0F478 > ~/.2fa/aws.gpg
set -eu -o pipefail
secretsFile="$1"
oathtool -b --totp -- "$(gpg2 --decrypt --quiet < "$secretsFile")" | xsel -bi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment