LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

oathtool

generates and validates one-time passwords for two-factor authentication

TLDR

Generate TOTP code from secret
$ oathtool --totp --base32 [SECRET_KEY]
copy
Generate HOTP code (counter-based)
$ oathtool --hotp --counter [1] --base32 [SECRET_KEY]
copy
Generate 8-digit code
$ oathtool --totp --base32 --digits [8] [SECRET_KEY]
copy
Validate a TOTP code
$ oathtool --totp --base32 [SECRET_KEY] [123456]
copy
Generate code with time window
$ oathtool --totp --base32 --now "[2024-01-15 12:00:00 UTC]" [SECRET_KEY]
copy
Use SHA256 algorithm
$ oathtool --totp=sha256 --base32 [SECRET_KEY]
copy
Show verbose output
$ oathtool --totp --base32 -v [SECRET_KEY]
copy

SYNOPSIS

oathtool [--totp[=alg]|--hotp] [--base32] [--digits num] [--counter num] [options] secret [otp]

DESCRIPTION

oathtool generates and validates one-time passwords for two-factor authentication. It supports both HOTP (RFC 4226, counter-based) and TOTP (RFC 6238, time-based) algorithms.TOTP is the standard used by authenticator apps (Google Authenticator, Authy, etc.). The secret key is typically provided as a base32 string during 2FA setup. Running oathtool with this secret generates the same codes as the authenticator app.For validation, provide both the secret and the code to verify. The window option allows for clock skew by accepting codes from adjacent time periods.HOTP uses an incrementing counter instead of time. Each code generation should increment the counter. This mode is less common but useful for hardware tokens.Different services use different parameters - some require 8 digits or SHA256. The verbose flag shows the calculation details for debugging setup issues.

PARAMETERS

--totp[=ALG]

Generate time-based OTP (sha1, sha256, sha512).
--hotp
Generate counter-based OTP.
-b, --base32
Secret is base32 encoded.
-d NUM, --digits NUM
Number of digits (default: 6).
-c NUM, --counter NUM
Counter value for HOTP.
-s SEC, --time-step-size SEC
Time step in seconds (default: 30).
-S TIME, --start-time TIME
Start time for TOTP (Unix timestamp or ISO).
-N TIME, --now TIME
Use specified time instead of current.
-w NUM, --window NUM
Window for validation.
-v, --verbose
Show detailed output.

INSTALL

sudo apt install oathtool
copy
sudo dnf install oathtool
copy
sudo apk add oath-toolkit-oathtool
copy

CAVEATS

Secrets must be kept secure - anyone with the secret can generate codes. System time must be accurate for TOTP. No built-in secret storage - integrate with password managers. Command history may expose secrets - use environment variables or files for scripting.

HISTORY

oathtool is part of the OATH Toolkit project, implementing the Initiative for Open Authentication (OATH) standards. It was developed to provide open-source HOTP and TOTP implementations. The toolkit also includes PAM modules for system authentication and a library for developers.

SEE ALSO

pass-otp(1), 2fa(1), gpg(1), openssl(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid