OTP on the CLI

I have used a Yubikey as the primary way of managing my OTP codes for several years now. I usually use the Yubico Authenticator application, which is great. But, sometimes when I am working in my editor and terminal I just want to stay there.

So I wrote this little wrapper around ykman to make my life a bit easier. It is very simplistic, but it gets the job done for me. To use, just make sure it is executable and in your path, then you can just type something like otp github and it will stick the code into your clipboard, assuming you have xclip installed.

# alias pbcopy="xclip -sel clip"
if [ -z "$1" ]
   echo 'need account name '
   exit 1
    CODE=$(ykman oath accounts code $1 | awk '{print $NF}')
echo $CODE | xclip -sel cli 

The only error checking this does is check to ensure you pass an account name. If you have multiple accounts that match your account name, things will be weird. I also do not think this will handle codes that require touch.

How to reply to this post