Skip to content

Instantly share code, notes, and snippets.

@oofnikj
Created June 21, 2020 06:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oofnikj/9d6a81cd591a3b67ef7f18eee55f1f06 to your computer and use it in GitHub Desktop.
Save oofnikj/9d6a81cd591a3b67ef7f18eee55f1f06 to your computer and use it in GitHub Desktop.
TOTP CLI generator
#!/usr/bin/env python
# put this file in your $PATH to generate TOTP from command line (don't forget to `chmod +x`)
import os
import sys
import pyotp
import pyperclip
try:
TOTP_SECRET_FILE = os.path.expanduser(sys.argv[1])
except IndexError:
sys.stderr.write(f"Usage: {sys.argv[0]} /path/to/base32_totp_secret\n")
exit(1)
totp = pyotp.TOTP(open(TOTP_SECRET_FILE).read()).now()
pyperclip.copy(totp)
print(totp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment