-
-
Save thibthibaut/7190af4cd47d23bfcf10267e14bdc048 to your computer and use it in GitHub Desktop.
Two Factor Authentication on command line
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
#!/usr/bin/env bash | |
# !! requires oathtool and gpg !! | |
# very very inspired by | |
# https://www.sendthemtomir.com/blog/cli-2-factor-authentication | |
# $HOME/.2fa should look like this : | |
# service_name=code | |
# service_name2=code2 | |
# and should be encrypted with gpg this way : | |
# gpg --cipher-algo AES256 -c ~/.2fakeys | |
if [ -z $1 ]; then | |
echo | |
echo "Usage:" | |
echo " 2fa protonmail" | |
echo | |
echo "Configuration: $HOME/.2fakeys.gpg" | |
echo "Format: name=key" | |
exit | |
fi | |
DECRYPTED="$(gpg -d $HOME/.2fakeys.gpg)" | |
OTPKEY="$(echo "$DECRYPTED" | sed -n "s/${1}=//p")" | |
if [ -z "$OTPKEY" ]; then | |
echo "$(basename $0): Unknown Service Name '$1'" | |
$0 | |
exit | |
fi | |
# Genrate the 2FA code | |
oathtool --totp -b "$OTPKEY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment