pam_oath

提供: ArchWiki
2019年3月1日 (金) 00:55時点におけるKusakata (トーク | 投稿記録)による版 (カテゴリ変更)
ナビゲーションに移動 検索に移動

OATH Toolkit はワンタイムパスコード (OTP) を使用する2段階認証を実現します。RFC 標準になっている2つの OTP 手法に対応 (HOTP, TOTP)。OTP を生成するアプリケーションは iOS, Android, Blackberry などの端末で使うことができます。Google Authenticator と同じように認証メカニズムは Linux の PAM システムと統合されています。このページではインストールと設定について説明します。

インストール

oath-toolkit パッケージをインストールしてください。

oath の設定

oath のシードは16進数の数字で、ユーザーごとに一意である必要があります。新しいシードを生成するには、以下のコマンドラインを使用します:

$ head -10 /dev/urandom | sha512sum | cut -b 1-30
1ab4321412aebcw

この記事では上記のシードを例として使用しますが、同じシードを実際に設定するときに使ってはいけません。oath はユーザーごとに必要で、設定ファイル /etc/users.oath の中にリンクします。root でファイルを作成して、ユーザーのシードを記述してください:

/etc/users.oath
# Option User Prefix Seed
HOTP/T30/6 user - 1ab4321412aebcw

ファイルは root からしかアクセスできないようにします:

# chmod 600 /etc/users.oath
# chown root /etc/users.oath

PAM の設定

特定のサービスだけで oath を有効にするには、例えば ssh なら /etc/pam.d/sshd ファイルを編集してファイルの先頭に以下の行を追加します:

auth	  sufficient pam_oath.so usersfile=/etc/users.oath window=30 digits=6

これで正しい oath コードを入力したときに認証が通るようになります。認証を必須にして pam スタックの処理を止めるようにしたい場合は以下のように設定します:

auth	  required pam_oath.so usersfile=/etc/users.oath window=30 digits=6

oath パスの記録

現在の oath パスが必要な場合は以下のコマンドを実行:

oathtool -v -d6 1ab4321412aebcw

上記の 1ab4321412aebcw は適当なシードに置き換えてください。以下のような表示がされます:

Hex secret: 1ab4321412aebc
Base32 secret: DK2DEFASV26A====
Digits: 6
Window size: 0
Start counter: 0x0 (0)

820170

最後の数字は実際にログインに使用することができます。また、Base32 secret は qr コードを生成するのに必要な文字列です。qr コードを生成するには qrencode パッケージをインストールして次のコマンドを実行:

qrencode -o user.png 'otpauth://totp/user@machine?secret=DK2DEFASV26A===='

user, machine, DK2DEFASV26A==== は適当な文字列に置き換えてください。生成が完了したら、お好きな画像作成アプリケーションで qrcode を視覚化して使用することができます。FreeOTP を使用して png のスクリーンショットを撮影し、必要になったときに OTP パスを表示するのが一番簡単です。

ノート: The secret key of your users is the most important information in this system. Once you setup a phone to provide OTP, it does have that key. The qr code in that png file does have that key. You need to take extra care of this file. They should only be stored on encrypted medium (Your phone need to be using encryption for any sane level of security). If not even confined in a sandbox like Samsung Knox to prevent third party application to potentially access them.

参照