Last active
April 30, 2023 18:33
-
-
Save Kas-tle/35222e0e021d02cfabc63cdecdf353a4 to your computer and use it in GitHub Desktop.
UNIX OTP Tool
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
[ | |
{ | |
"account": "My first account [email protected]", | |
"key": "8SDFYSDNFSDFY89SDFSDF" | |
}, | |
{ | |
"account": "My second account [email protected]", | |
"key": "23849HFGDKLDFIAE" | |
} | |
] |
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
OTP_STORAGE='/full/path/to/otp.json' | |
PS3="Retrieve OTP: " | |
readarray -t options < <(jq '.[].account' ${OTP_STORAGE}) | |
echo | |
select menu in "${options[@]}"; | |
do | |
echo | |
echo "Token for ${menu}:" | |
secret=$(jq -r --arg TOKEN_INDEX $REPLY '.[($TOKEN_INDEX | tonumber - 1)].key' ${OTP_STORAGE}) | |
token=$(oathtool --totp -b ${secret}) | |
echo ${token} | |
# change this line below to use your system's clipboard! | |
# WSL: clip.exe | |
# MacOS: pbcopy | |
# Ubuntu: xclip -i | |
printf ${token} | pbcopy | |
echo | |
break; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
MacOS
Install Homebrew if you don't already have it: https://brew.sh/
Ubuntu & Debian
Usage
Simply add keys and an account name for each to
otp.json
. You can then runotp
as a command and enter a number for the one time password of the account you'd like to obtain. The OTP will be displayed and, assuming you've set it up, copied to your clipboard.