-
-
Save vjt/a6641c707402cc8f28c7c9d003f3c03f to your computer and use it in GitHub Desktop.
2FA from the mac command line using oathtool-toolkit without much fuss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- 2fa Command Line -*- | |
# | |
# Uses oath-toolkit http://nongnu.org/oath-toolkit/ | |
# to generate 2FA OTPs and copies them in the Mac's | |
# clipboard using pbcopy(1). For other UNIX systems | |
# you can just strip the pbcopy at the bottom. | |
# | |
# In the dir below you should put TOTP token seeds, | |
# one per file, naming it after the service you are | |
# authenticating against. | |
# | |
# Each service uses different approaches to let you | |
# know (or to try to prevent you from knowing) your | |
# TOTP seed: it's up to you to find it out. Anyway, | |
# for TOTP to work, you *need* the seed, so it will | |
# be hidden, somewhere, for you to find out. | |
# | |
# - [email protected] Thu Oct 12 22:53:11 CEST 2017 | |
# | |
# WTFPL license (http://www.wtfpl.net/) | |
# | |
BASEDIR=~/Documents/2fa | |
service=$1 | |
if [ -z "$service" ]; then | |
echo "Usage: $0 <service>" | |
exit 1 | |
fi | |
if ! echo "$service" | grep -Eq '[a-zA-Z0-9]+'; then | |
echo "Invalid service name: $service" | |
exit 2 | |
fi | |
file="$BASEDIR/$service" | |
if [ ! -f "$file" ]; then | |
echo "Unknown service: $service" | |
exit 3; | |
fi | |
code=$(cat $file) | |
oathtool --totp -b "$code" | pbcopy | |
echo "Copied to the clipboard" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment