Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
.ssh/configを管理する .ssh/configで管理する
Search
Ken’ichiro Oyama
November 03, 2016
Technology
11k
15
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
.ssh/configを管理する .ssh/configで管理する
PHPカンファレンス2016
Ken’ichiro Oyama
November 03, 2016
More Decks by Ken’ichiro Oyama
See All by Ken’ichiro Oyama
Introducing RFC9111 / YAPC::Fukuoka 2025
k1low
2
5.5k
Design and implementation of "Markdown to Google Slides" / phpconfuk 2025
k1low
1
940
analysis パッケージの仕組みの上でMulti linter with configを実現する / Go Conference 2025
k1low
1
780
Flight recorder at the application layer (NOT the FlightRecoder newly added at Go 1.25) / Fukuoka.go #22
k1low
0
170
ソフトウェア開発におけるインターフェイスという考え方 / PHPerKaigi 2025
k1low
12
6.3k
Parsing HCL/CUE / Fukuoka.go #21
k1low
0
11k
実践 net/http Middleware パターン / Kizuku.go Vol.1
k1low
2
450
Cleanup handling in Go / Go Conference 2024
k1low
7
4.1k
CI/CDがあたりまえの今の時代にAPIテスティングツールに求められていること / CI/CD Test Night #7
k1low
18
12k
Other Decks in Technology
See All in Technology
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
130
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
170
AWS Security Agent といっしょに脅威モデリングをやってみよう
amarelo_n24
1
180
AIネイティブな開発のサプライチェーンリスク対策 〜激動の開発現場でリスクに立ち向かう〜【ZennFes】
cscengineer
PRO
2
140
Agent Skills設計で柔軟性と硬さのバランスが難しい話
nassy20
0
150
OTel × Datadog で 「AI活用」を計測し、改善に繋げる
shihochan
2
450
ロボティクスの技術 / Robotics Technology
ks91
PRO
0
110
アンオフィシャルな、オフィシャルからのお願い
wyamazak_devrel
0
140
インシデントレスポンス演習 I / Incident Response Exercise I
ks91
PRO
0
100
マルチアカウント環境での コーディングエージェントを使った障害調査が大変なので AIエージェントにReadOnly権限を付与してみた / ReadOnly AI Agents for Multi-Account AWS Incident Response
yamaguchitk333
2
110
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
180
攻撃者視点で考えるDetection Engineering
cryptopeg
3
2k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
So, you think you're a good person
axbom
PRO
2
2.1k
We Have a Design System, Now What?
morganepeng
55
8.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Building AI with AI
inesmontani
PRO
1
1.1k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Code Review Best Practice
trishagee
74
20k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
170
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Transcript
.ssh/configを管理する .ssh/configで管理する Kenʼichiro Oyama Fusic Co.,Ltd. 2016.11.3 1 PHPカンファレンス2016
みなさん SSHしてますか? 2 PHPカンファレンス2016
わたしは SSHしてます 3 PHPカンファレンス2016
?> NEXT PHPカンファレンス2016のテーマ 4 PHPカンファレンス2016
SSHとNEXT 5 PHPカンファレンス2016 FTP SSH + パスワード
SSH + 公開鍵認証 「SSHしたら負け」 <- たぶんここがNEXT Docker、EC2 Run Command、etc “NEXT”ではないですが、 今⽇は”SSH + 公開鍵認証”で少しだけ役に⽴ちそ うな話をします
Who 6 PHPカンファレンス2016
k1LoW Kenʼichiro Oyama @k1LoW Fusic Co.,Ltd. エンジニア
基盤ユニット テックリード GitHub organizations fukuokarb / dotcake / emacs-jp / etc. awspecというAWS⽤のテストツールを作って います https://github.com/k1LoW/awspec 7 PHPカンファレンス2016
普段のわたし 複数のプロジェクト 開発中 運⽤中 複数のサーバ
プロジェクト単位 ロール単位(Web、DB、etc) 本番、ステージング、テスト 8 PHPカンファレンス2016
イメージ 複数のプロジェクトの複数のサーバにSSH 9 PHPカンファレンス2016
~/.ssh/config SSH接続の管理をするための設定ファイル ~/.ssh/configはユーザごとの設定ファイル 10 PHPカンファレンス2016 Host github.com
User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa
/home/k1low/.ssh/config 管理しているサーバへSSH接続するための設定 を記載 秘密鍵も .ssh/ 以下に配置 プロジェクトごと、ロールごと、サーバごとな
どで分けることが多い id_rsaは使わない 秘密鍵だけでなく、その他の接続設定も重要 HostnameやUser ProxyCommandとか 11 PHPカンファレンス2016
.ssh/config どうやって管理していますか? 12 PHPカンファレンス2016
.ssh/configの管理 configのバックアップ/リストア 秘密鍵のバックアップ/リストア サーバ接続情報の追加/削除 チームメンバーへの共有
踏み台サーバなど他サーバへの設置 13 PHPカンファレンス2016
configと秘密鍵に分かれていて ⾯倒 14 PHPカンファレンス2016
configは分割できないので メンバーへの共有も⾯倒 15 PHPカンファレンス2016
今のconfigとバックアップした configのマージも⾯倒 16 PHPカンファレンス2016
sconb 17 PHPカンファレンス2016
sconb “Ssh CONfig Buckup tool” .ssh/config専⽤のバックアップツール https://github.com/k1LoW/sconb
gem install sconb でインストール ※本⽇も⼤変お世話になっているCONBUとは無関係です 18 PHPカンファレンス2016
使い⽅ 19 PHPカンファレンス2016
バックアップ 20 PHPカンファレンス2016 $ sconb dump > ssh_config.json $ cat
ssh_config.json { "github.com": { "Host": "github.com", "User": "git", "Hostname": "github.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/github_rsa" ] }, ...
絞り込んでバックアップ 21 PHPカンファレンス2016 $ sconb dump example > ssh_config.json $ cat
ssh_config.json { ”example.com": { "Host": ”example.com", "User": ”k1low", "Hostname": ”dev.example.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/example_rsa" ] } }
リストア 22 PHPカンファレンス2016 $ sconb restore < ssh_config.json Host github.com
User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa ... $ sconb restore < ssh_config.json > ~/.ssh/cofing
秘密鍵も含めて1ファイル化 23 PHPカンファレンス2016 $ sconb dump --all > ssh_config_with_key.json $
cat ssh_config_with_key.json { "github.com": { "Host": "github.com", "User": "git", "Hostname": "github.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/github_rsa" ], "IdentityFileContent": [ "-----BEGIN RSA PRIVATE KEY-----\nMIIEpXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... ] }, ...
秘密鍵のリストア 24 PHPカンファレンス2016 $ sconb keyregen < ssh_config_with_key.json Regenerate ~/.ssh/github_rsa
... ...
つまり ssh_config <-> JSON のコンバータ 25 PHPカンファレンス2016
パイプで各種UNIXコマンドとも 連携できる 26 PHPカンファレンス2016
jqを使ったssh_confg.jsonのマージ jq: JSONをいい感じに操作できるコマンド 27 PHPカンファレンス2016 $ jq -s '.[0]
+ .[1]’ a.json b.json | sconb restore > ~/.ssh/config
.ssh/configを管理する sconbはおいしい 28 PHPカンファレンス2016
別の視点から 29 PHPカンファレンス2016
普段のわたし(再掲) 複数のプロジェクト 開発中 運⽤中 複数のサーバ
プロジェクト単位 ロール単位(Web、DB、etc) 本番、ステージング、テスト 30 PHPカンファレンス2016
イメージ(再掲) 複数のプロジェクトの複数のサーバにSSH 31 PHPカンファレンス2016
突然の◯penSSLの脆弱性発表 32 PHPカンファレンス2016
インベントリ情報 「サーバにイントールされているパッケージの バージョン⼀覧を再度確認して欲しい」 現在稼働しているサーバ数⼗台 まったく別の時期にまったく別のサービスを 構築している
全部SSHでログインして確認。。。??そして その後まとめるの。。。? ツラみがある。。。 33 PHPカンファレンス2016
34 koma PHPカンファレンス2016
koma エージェントレスでリモートホストのインベン トリ情報を収集するツール https://github.com/k1LoW/koma 類似ツール: ohai /
facter gem install koma でインストール `ssh` を `koma ssh` に変えるだけで、リモ ートホストのインベントリ情報をJSONで取得 できる 35 PHPカンファレンス2016
koma ssh 36 PHPカンファレンス2016 $ koma ssh example.com {
"memory": { "swap": { "cached": "652kB", "total": "2097148kB", "free": "2091376kB" }, "total": "1019956kB", "free": "255104kB", "buffers": "310644kB", "cached": "185748kB", ...
koma keys (収集できるインベントリ情報) memory ec2 (disabled) hostname
domain fqdn platform platform_version filesystem cpu virtualization kernel block_device package user group service PHPカンファレンス2016 37
koma run-command 38 PHPカンファレンス2016 $ koma run-command example.com,example.jp uptime {
"example.com": { "uptime": { "exit_signal": null, "exit_status": 0, "stderr": "", "stdout": " 00:18:10 up 337 days, 4:51, 1 user, load average: 0.08, 0.02, 0.01\n" } }, "example.jp": { "uptime": { ...
そう、.ssh/configが設定されて いればね! 39 PHPカンファレンス2016
.ssh/configで管理する 40 PHPカンファレンス2016
ssh_config形式で管理する .ssh/configで管理する 41 PHPカンファレンス2016
koma with ssh_config komaはssh_config形式のフォーマットを STDINから読み込んで実⾏することができる Vagrant上のOSのcpu情報を取得 sconbをでHostをフィルタリング
42 PHPカンファレンス2016 $ vagrant ssh-config | koma ssh --key cpu $ sconb dump dev.* | sconb restore | koma ssh
Vuls 43 PHPカンファレンス2016
Vuls “VULnerability Scanner” バルス Linux/FreeBSD向けの脆弱性スキャンツール Ubuntu、Debian、CentOS、Amazon
Linux、RHELに対応 標準のTUIだけでなくVulsRepoというWebビューワもある NVDやJVNの脆弱性情報などを使⽤してスキャン スキャン対象のサーバーへは “SSH” で接続 TOMLで設定を記述 44 PHPカンファレンス2016
SSH。。。だと。。? 45 PHPカンファレンス2016
ssh_config_to_vuls_config 46 PHPカンファレンス2016
ssh_config_to_vuls_config ssh_config形式をVuls⽤のTOMLファイル形式 に変換 sc2vcコマンド https://github.com/k1LoW/ssh_config_to_vuls_config gem
install ssh_config_to_vuls_config でインストール (当然)sconbでフィルタリングも可能 47 PHPカンファレンス2016 $ cat ~/.ssh/config | sc2vc > vuls_config.toml $ sconb dump dev.* | sconb restore | sc2vc > filtered_config.toml
.ssh/config -> JSON JSON -> .ssh/config JSON -> koma JSON
-> Vuls 48 PHPカンファレンス2016
NEXT 49 PHPカンファレンス2016
ssh_configファイルを集約すれば サーバインベントリ情報も 脆弱性情報も 管理できるのでは? 50 PHPカンファレンス2016
こんなサーバを 51 PHPカンファレンス2016
.ssh/configで管理 52 PHPカンファレンス2016
komad (仮) sconbなJSONをAPI or SCP経由で登録 ssh_config + komaでサーバインベントリ情報
を収集管理 ssh_config + Vulsで脆弱性情報を収集管理 koma run-commandでSSHを通じた外形監視 ちょっと変わったサーバ管理/監視システムが できそう 53 PHPカンファレンス2016
.ssh/configで管理する 54 PHPカンファレンス2016
まとめ 55 PHPカンファレンス2016
まとめ .ssh/configをsconbでJSON形式にすることで 管理容易性、再利⽤性を向上 .ssh/configやssh_config形式のフォーマット を⼊⼒として動くエージェントレスなサーバイ ンベントリ収集ツール koma
Vulsの設定の元として.ssh/configの活⽤ ssh_configを活⽤したサーバ管理/監視システ ムkomad(仮)の可能性 56 PHPカンファレンス2016
さっそく .ssh/configを整理しましょう 古い設定、残っていませんか? 57 PHPカンファレンス2016
Thank you! Fusicはテクノロジーが 好きなエンジニアを募集しています https://fusic.github.io 58
?> 59 PHPカンファレンス2016
NEXT 60 PHPカンファレンス2016
イメージ(再掲) 複数のプロジェクトの複数のサーバにSSH 61 PHPカンファレンス2016
サーバのユーザを管理したい どのサーバにどのユーザがSSHログインできる のか 簡単なものでいい ある程度でいい もしくはSSHログインできる情報をもらえるよ
うにしたい 公開鍵とか秘密鍵とかの管理 62 PHPカンファレンス2016
⼀般的な⽅法 63 PHPカンファレンス2016
PAM Pluggable Authentication Module PAMを使ってユーザ管理サーバ(認証基盤)に 認証の要求をもらう ADとかLDAPが⼀般的らしい
ただ個⼈的にはSTNS推し シンプル 設定がTOML 認証サーバ側をサーバレスにできそう http://qiita.com/shogomuranushi/items/ f09fcdeb146b45452403 新イケメンことP⼭さん(@pyama86)が開発している 64 PHPカンファレンス2016
だかしかし 65 PHPカンファレンス2016
プロジェクトを横断できない 完全弊社都合 66 PHPカンファレンス2016
komad(仮)がssh_configを 払い出したらどうだろう 67 PHPカンファレンス2016
komad(仮)にもらう API経由でssh_config.jsonをもらう 68 PHPカンファレンス2016
どうでしょう。。? イビツなのは承知 komad(仮)サーバの運⽤。。。 無理があるか。。。 69 PHPカンファレンス2016
Thank you! Fusicはテクノロジーが 好きなエンジニアを募集しています https://fusic.github.io 70