PCFreak Logo (c) Der PCFreak

OTP token for bash

oathtool emulating token in bash

If you ever have to emulate a OTP token in bash, you could do this easily with oathtool. For Debian based systems compile it yourself or just install the packages from the latest testing release, they work well on stable versions, too.

I wrote a small bash script to emulate a OTP token. It can be used to emulate a time-based Google-Authenticator token or a time-based c200 token from http://gooze.eu You can modify it to also be able to emulate event-based tokens, just replace „–totp“ with „–hotp“ and replace the time step (-s) with a counter value (-c).

Here is the code:

#!/bin/bash
#
secret=38217FF224B2352885AABAA4DF3C13773AC5B883
clear
while [ 1 = 1 ]; do
 # for Google-Authenticator enable next line
 # make sure youe have secret in base32
 #password=$(oathtool --totp -b -s 30s $secret)
 # for c200 Token (gooze.eu) enable next line
 password=$(oathtool --totp -s 60s $secret)
 seconds=$(date +%S)
 echo "##################################"
 echo "#         Software-Token         #"
 echo "##################################"
 echo -n '#             '
 if [ "$seconds" -gt 56 ] ; then
    echo -n -e "\e[1;31m$password\e[0m"
 #enable next 2 lines for a 30s interval
 # elif [ "$seconds" -gt 26 -a "$seconds" -lt 30 ]; then
 #    echo -n -e "\e[1;31m$password\e[0m"
 else
    echo -n "$password"
 fi
    echo '             #'
 echo "################################$seconds"
 echo ""
 sleep .3
 clear
done

 

Feel free to modify it to your needs.