手順
- インストール
- バージョン
- ヘルプ
- 使ってみる
1. インストール
sudo apt install -y oathtool
2. バージョン
$ oathtool --version oathtool (OATH Toolkit) 2.6.1 Copyright (C) 2015 Simon Josefsson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Simon Josefsson.
3. ヘルプ
$ oathtool --help oathtool 2.6.1 Generate and validate OATH one-time passwords. Usage: oathtool [OPTIONS]... [KEY [OTP]]... -h, --help Print help and exit -V, --version Print version and exit --hotp use event-based HOTP mode (default=on) --totp[=STRING] use time-variant TOTP mode (possible values="sha1", "sha256", "sha512" default=`sha1') -b, --base32 use base32 encoding of KEY instead of hex (default=off) -c, --counter=COUNTER HOTP counter value -s, --time-step-size=DURATION TOTP time-step duration (default=`30s') -S, --start-time=TIME when to start counting time steps for TOTP (default=`1970-01-01 00:00:00 UTC') -N, --now=TIME use this time as current time for TOTP (default=`now') -d, --digits=DIGITS number of digits in one-time password -w, --window=WIDTH window of counter values to test when validating OTPs -v, --verbose explain what is being done (default=off) Report bugs to: oath-toolkit-help@nongnu.org oathtool home page: <http://www.nongnu.org/oath-toolkit/> General help using GNU software: <http://www.gnu.org/gethelp/>
4. 使ってみる
secret=二要素認証の秘密鍵 otp="$(oathtool --totp -d 6 -s 30s -b $secret)" echo $otp
出た。
username=ユーザ名 password=パスワード secret=二要素認証の秘密鍵 curl -u $username:$password -H "X-GitHub-OTP: $(oathtool --totp -d 6 -s 30s -b $secret)" https://api.github.com/users/$username
JSONが返ってきた。OK。
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
$ uname -a Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux