勉強会向けサーバを作ってみる2 / rasbian jessieを試す/ google...
TRANSCRIPT
![Page 1: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/1.jpg)
勉強会向けサーバを作ってみる 2Rasbian jessie を試す
Google Authenticator のパスコードを作る
KenichiroMATOHARA(matoken)<[email protected]>
鹿児島 Linux 勉強会 2015.11 ( 第 11 回 ) 20151113( 金 )
![Page 2: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/2.jpg)
2
Kenichiro MATOHARA
@matoken
http://matoken.org/
興味
Linux
FLOSS
OpenSteetMap
電子工作
:
お仕事募集中 !
![Page 3: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/3.jpg)
3
最近
猫に埋もれた生活
![Page 4: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/4.jpg)
猫アタック !
NotePC 基板半死亡 (3G/Wi-Fi 死亡 )
NotePC 液晶 x2 死亡
![Page 5: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/5.jpg)
5
鹿児島らぐ / 鹿児島 Linux 勉強会
今回で 12 回目
前回は 2 月 3 4 5 6 7 8 9 10 11……9 ヶ月ぶり orz
もし集まりたいといった場合には ML 等で告知して勝手に開催して
も OK
matohara も出来ることは手伝います !
![Page 6: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/6.jpg)
6
勉強会向けサーバを作ってみる 2- 端末の共有をブラウザベースでお手軽に -
![Page 7: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/7.jpg)
7
端末の共有
前回 →
http://www.slideshare.net/matoken/ss-51975843
GNU Screen/Tmux 等
ー>リモートログインが面倒
GoTTY( https://github.com/yudai/gotty )ウェブブラウザ経由で端末が共有できる
ー>お手軽
![Page 8: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/8.jpg)
8
GoTTY の導入
go の導入
% sudo apt install golang
go get で GoTTY の導入 (~/usr/local/go 以下に導入 )
GOPATH=~/usr/local/go go get github.com/yudai/gotty
![Page 9: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/9.jpg)
9
GoTTY の利用例
% ~/usr/local/go/bin/gotty top
2015/11/13 06:26:33 Permitting clients to write input to the PTY.
2015/11/13 06:26:33 Server is starting with command: tmux new -A -s gotty
2015/11/13 06:26:33 URL: http://127.0.0.1:8080/
2015/11/13 06:26:33 URL: http://[::1]:8080/
2015/11/13 06:26:33 URL: http://[fe80::a27e:a3b8:cfa7:22a6]:8080/
2015/11/13 06:26:33 URL: http://192.168.2.217:8080/
2015/11/13 06:26:33 URL: http://[fe80::85e0:9218:1854:8531]:8080/
この状態で URL: 〜 にブラウザでアクセスすると top コマンドが実行されるのが確認できる
![Page 10: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/10.jpg)
10
![Page 11: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/11.jpg)
11
$ gotty bash のようにすると bash が起動するが操作できない
--permit-write, -w オプションを利用することで書き込みが可能になる
$ gotty -w bash
しかし複数のブラウザでアクセスするとそれぞれ別のセッションになってしまう.みんなでひとつの端末を叩きたい……
2015/08/23 14:47:42 Server is starting with command: bash
2015/08/23 14:47:46 New client connected: 127.0.0.1:36194
2015/08/23 14:47:46 Command is running for client 127.0.0.1:36194 with PID 28469
2015/08/23 14:48:56 New client connected: 127.0.0.1:36208
2015/08/23 14:48:56 Command is running for client 127.0.0.1:36208 with PID 29315
![Page 12: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/12.jpg)
12
GoTTY
bash1
bash3
bash2
![Page 13: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/13.jpg)
13
GoTTY bash
みんなで 1 つの端末を利用したい
![Page 14: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/14.jpg)
14
マルチユーザのセッションを
README.md に以下のような記述が,tmux を利用すると行けるらしい
Sharing with Multiple Clients
Gotty starts a new process when a new client connects to the server. This means users cannot share a single terminal with others by default. However, you can use terminal multiplexers for sharing a single process with multiple clients.
For example, you can start a new tmux session named gotty with top command by the command below.
$ gotty tmux new -A -s gotty top
This command doesn't allow clients to send keystrokes, however, you can attach the session from your local terminal and run operations like switching the mode of the top command. To connect to the tmux session from your terminal, you can use following command.
$ tmux new -A -s gotty
By using terminal multiplexers, you can have the control of your terminal and allow clients to just see your screen.
![Page 15: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/15.jpg)
15
tmux の 1 つのセッションをみんなで叩く
$ gotty -w tmux new -A -s gotty
-w : 入力可能
tmux new -A -s gotty : gotty というセッション名で tmux を起動
GNU Screen でも出来ないかとセッション名を同じように
gotty にして multiuser on にしてみましたがこれだけでは
うまく行きませんでした. GoTTY 本体に手を入れる必要があるかもしれません.
![Page 16: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/16.jpg)
16
midori
Chromium
Android 版 Chrome
![Page 17: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/17.jpg)
17
プロジェクタで画面を映してみんなでひとつの端末を叩くことが出来るようになる
勉強会とかで重宝しそう
セキュリティは BASIC 認証やランダム URL , SSL 化などが可
能だけど jail 環境で必要なときだけ立ち上げてセッションごとに初期化するといった運用が良さそう
![Page 18: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/18.jpg)
18
Rasbian jessie!
![Page 19: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/19.jpg)
19
Rasbian?
Debian ベースの Rasberry Pi 用 OS
"FrontPage - Raspbian" http://www.raspbian.org/
![Page 21: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/21.jpg)
21
Raspberry Pi リリース時から wheezy ベースの Rasbian だった
( 当時は確か testing)
Debian jessie のリリースは 2015 年 04 月 25 日
Rasbian jessie は 2015 年 09 月 25 日リリース (https://downloads.raspberrypi.org/raspbian/release_notes.txt)
現在は Rasbian wheezy/jessie ともにサポート中
Debian jessie は ARMv6 はサポート外だけど Rasbian jessieは ARMv6 の Raspberry Pi(B/B+/A/A+) でも動作する !
未だ Rasbian jessie の事例は少ないので Rasbperry Pi 特有の
事柄は wheezy の方が良いことも
![Page 22: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/22.jpg)
22
Rasbian jessie を試す
導入
wheezy と一緒
ダウンロードして hash を確認して SD Card に書き込む
@ebijun Raspberry Pi の OS 導入手順はみんな知っているので試してもらいやすい
"NetBSD/RPI.rst at master · ebijun/NetBSD"https://github.com/ebijun/NetBSD/blob/master/Guide/RPI.rst
![Page 23: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/23.jpg)
23
気づいたこと
raspi-config GUI 版が登場 ( rc_gui )
いきなり X が起動して自動ログインしてる
コンソールも自動ログインしている
GUI でネットワーク設定を行うと /etc/network/interfaces, /etc/wpa_supplicant/wpa_supplicant.conf などが書き換わ
る ( LXPanel )
一度 GUI で設定しちゃえば X を使わない時でも Wi-Fi に繋がるので便利
(もしかして以前から ? )
avahi が導入済み & 自動起動
raspberrypi.local という名前で呼べる
dhcp 環境で便利
![Page 24: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/24.jpg)
24
rc_gui
![Page 25: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/25.jpg)
25
LXPanel のネットワーク設定
パスフレーズが平文のままなので注意
psk="hogefuga”
wpa_passphrase でパスフレーズを暗号化して置き換えたほうが心持ち安心
$ wpa_passphrase ssid passphrase
network={
ssid="ssid"
#psk="hogefiga"
psk=a0c528edbaacde16d49e3788d341286a333cb66417
30d5d9d77fae06dad1f1b6
}
![Page 26: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/26.jpg)
26
Google Authenticator のパスコードをお手軽に
![Page 27: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/27.jpg)
27
多要素認証
ユーザ名 + パスワード
⇓
ユーザ名 + パスワード + ワンタイムパスワード (OTP)
RFC 6238 で標準化されていて色々なサービスで利用できる
Google/AWS/GitHUB/Dropbox/Evernote/Facebook……
pam のライブラリもあるので自サーバの ssh でも利用できる !(libpam-google-authenticator)
OPT
OTP 生成器
スマホアプリケーション
電話
SMS
携帯メール
:
![Page 28: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/28.jpg)
28
OTP 生成器 ( 液晶画面タイプ )
壊れたことがある
1 つに付き 1 アカウントなのでたくさん必要に
http://japan.emc.com/security/rsa-securid/rsa-securid-hardware-tokens.htmhttp://onlinenoram.gemalto.com/SafeNet-IDProve-100-6digit-OTP-Token/M/B002CRN5X8.htm
![Page 29: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/29.jpg)
29
OTP USB タイプ
未検証
入力が必要無いのでお手軽そう
![Page 30: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/30.jpg)
30
スマホアプリ
Android/iOS の他大抵のプラットホーム向けにある
"Google 認証システム - Google Play の Android アプリ " https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2"IIJ、ワンタイムパスワード管理アプリケーション「 IIJ SmartKey」を提供
開始 | 2015 年 | IIJ" http://www.iij.ad.jp/news/pressrelease/2015/0403.html
![Page 31: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/31.jpg)
31
Google 認証システム Android 版を常用
めんどい
![Page 32: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/32.jpg)
32
調べてみたら簡単に実装できた
#!/usr/bin/python
import hmac, base64, struct, hashlib, time, os, sys
def get_hotp_token(secret, intervals_no):
key = base64.b32decode(secret, True)
msg = struct.pack(">Q", intervals_no)
h = hmac.new(key, msg, hashlib.sha1).digest()
o = ord(h[19]) & 15
h = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000
return h
def get_totp_token(secret):
return get_hotp_token(secret, intervals_no=int(time.time())//30)
if( len(sys.argv) > 1):
secret = sys.argv[1]
elif( os.path.exists( os.environ["HOME"] + "/.google_authenticator" )):
f = open( os.environ["HOME"] + "/.google_authenticator" )
secret = f.readline().replace('\n','')
else:
print sys.argv[0] + " SECRETKEY"
exit(-1)
#for i in xrange(1, 10):
# print i, get_hotp_token(secret, intervals_no=i)
print get_totp_token(secret)
https://gist.github.com/matoken/8159502c4a87dc3b0341
![Page 33: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/33.jpg)
33
Android 版と比較
![Page 34: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/34.jpg)
34
awesome wm でショートカットに設定してみた
ショートカットキーで OTP が表示される
今は SECRETKEY をファイルベタ書き
なので gnome-keyring か何かに格納
したい
![Page 35: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/35.jpg)
35
% cat opt.sh
#!/bin/bash
while read line
do
echo $line
arr=( `echo $line | tr -s ',' ' '`)
echo ${arr[1]}.${arr[2]}
notify-send -t 10000 ${arr[1]} `~/script/google-authenticator.py ${arr[2]}`
done < ~/fuse/encfs/.2auths
% cat ~/fuse/encfs/.2auths
Google,6QHI5WW6H3FMJ2ZI
GitHUB,6QHI5WW6H3FMJ2ZI
micro,6QHI5WW6H3FMJ2ZI
ダミーです
![Page 36: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/36.jpg)
36
SECRETKEY の入手
アカウント設定時に表示される場合はメモしておく
QR Code の場合は先に通常の読み取りアプリで読み込んでメモ
Android 版 Google 認証システム &root を使える場合は以下の手順で入手可能
"Android の Google Authenticator のデータをダンプしてバックアップ
する | matoken's meme" http://matoken.org/blog/blog/2015/10/10/i-want-to-back-up-by-dumping-the-data-of-google-authenticator-of-android/
![Page 37: 勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る](https://reader033.vdocuments.pub/reader033/viewer/2022050806/587748801a28ab84388b4d61/html5/thumbnails/37.jpg)
37
マイコンでも実装できそう
AVR とかのマイコンで実装したら持ち歩きも出来そう
壊れても同じ SECRETKEY を流し込める
複数のサービスにも対応できる
紛失盗難時は耐タンパ性が問題かも ( すぐに変更すれば大丈夫 ?)
"Linux で avr 開発環境を構築する +mbed(20100612koedo94)" http://www.slideshare.net/matoken/linux-avrmbed20100612koedo94