I was searching for the most simplest 2FA app for a limited use case in my work Mac. I explored several apps like Authy, KeePassXC, and Auth, but none could match the elegance of a command-line tool: oath-toolkit. This handy tool lets you generate one-time passwords (OTPs) for any account directly from the terminal.
Why oath-toolkit?
- Faster and Lighter: No need of running bulky UI apps, oath-toolkit runs efficiently in the terminal.
- Super Simple: No UI navigation. Just one command in terminal and OTP is copied to clipboard.
How?
- Install oath-toolkit: https://formulae.brew.sh/formula/oath-toolkit
- Find Your Secret Key: You can get your secret key from the original QR code that you scan using 2FA app if your app doesn’t have option to show or export existing one. You’ll need this to generate OTPs.
- Command Time! Here’s the key command:
alias otp = `oathtool -s 30 -b --totp=SHA1 YOUR_SECRET | pbcopy`
- Replace
YOUR_SECRET
with your actual secret key. -s 30
sets the OTP validity time (30 seconds by default). This value is not user configurable. It depends on the provider.-b
skips any prompts.--totp=SHA1
defines the hashing algorithm.pbcopy
copies the generated OTP to your clipboard.