Skip to content

Instantly share code, notes, and snippets.

@michaelwestphal
Created January 10, 2023 20:03
Show Gist options
  • Save michaelwestphal/fb98bdf53bee5ad9b66575005a5a7b7a to your computer and use it in GitHub Desktop.
Save michaelwestphal/fb98bdf53bee5ad9b66575005a5a7b7a to your computer and use it in GitHub Desktop.
Kubikey OTP CLI script

A Yubikey, the commandline, and easily generating and copying a One-Time Password

  1. Install ykman via homebrew on the Mac.
brew install ykman
  1. Create bash/zsh function somewhere in your shell rc files
function otp() {
  code=$(ykman oath accounts code <ACCOUNT_NAME_HERE> -s)
  echo $code | tr -d '\n' | pbcopy
  echo $code
}
  1. Call otp whenever you need a OTP. In my case ykman asks me to touch my Yubikey and then provides the one-time code and uses pbcopy to place it in my clipboard right away.

References:

Improvements

  • Add the account name as an arg on the function
  • Add account-specific aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment