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で快適テレワーク
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
koedoyoshida
March 28, 2020
Technology
170
0
Share
sshで快適テレワーク
今まで:最強のSSH踏み台設定
これから:-J
温故知新:ワイルドカードマッチ
自宅サーバ活用:autossh&systemd
koedoyoshida
March 28, 2020
More Decks by koedoyoshida
See All by koedoyoshida
AlmaLinux国内、日本語サポートについて
koedoyoshida
0
150
OSC仙台プレ勉強会 AlmaLinuxとは
koedoyoshida
0
280
AlmaLinuxのセキュリティ機能評価と認証~FIPS140 3認証、CC認証 取得への取り組み~
koedoyoshida
0
53
AlmaLinux + KVM + Cockpit で始めるお手軽仮想化基盤 ~ 開発環境などでの利用を想定して ~
koedoyoshida
1
1k
DebConf25参加報告
koedoyoshida
0
50
AlmaLinux Users Meetup 2025 Summer / AlmaLinuxの活動
koedoyoshida
0
190
CentOS後継!業務システムで使えるAlmaLinux for Enterprise
koedoyoshida
0
270
AlmaLinux Users Meetup 2025 Summer / サイバートラストのAlmaLinuxへの取り組み
koedoyoshida
0
200
AlmaLinux 10 / 9.6 リリース! ―変わるところと変わらないところ―
koedoyoshida
0
3.4k
Other Decks in Technology
See All in Technology
BigQuery の Cross-cloud Lakehouse への歩み
phaya72
2
540
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
1k
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
45
46k
React、まだ楽しくて草
uhyo
7
4k
美味しいスイスチーズを作ろう🧀🐭
taigamikami
1
230
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
170
Javaで学ぶSOLID原則
negima
1
280
JEP 522 Deep Dive - G1 GC同期コスト削減によるスループット向上を徹底検証&解説
tabatad
1
720
noUncheckedIndexedAccess、3時間、1万円。 / noUncheckedIndexedAccess, 3 Hours, 10,000 JPY.
kaonavi
1
230
AIガバナンス実践 - 生成AIコネクタのデータ漏洩リスクと実務対策
knishioka
0
170
「気づいたら仕事が終わっている」バクラクAIエージェント本番運用の裏側 / layerx-bakuraku-aie2026
yuya4
18
9.4k
Spring AI × MCP 入門〜AIエージェントへのツール公開、境界設計から始める最小構成 〜
yuyamiyamoto
0
210
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Test your architecture with Archunit
thirion
1
2.3k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
600
Abbi's Birthday
coloredviolet
2
7.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to make the Groovebox
asonas
2
2.2k
Ruling the World: When Life Gets Gamed
codingconduct
0
240
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
210
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Transcript
SSHで快適テレワーク 吉田@板橋
ネタ • 今まで:最強のSSH踏み台設定 • これから:-J • 温故知新:ワイルドカードマッチ • 自宅サーバ活用:autossh
今まで:最強のSSH踏み台設定 .ssh/config: # https://qiita.com/kawaz/items/a0151d3aa2b6f9c4b3b8 Host */* ProxyCommand ssh -W "$(basename
"%h")":%p "$(dirname "%h")" #ホスト鍵無条件に受け入れて、ファイルを更新 StrictHostKeyChecking no Host *+* ProxyCommand ssh -W "$(sed -E 's/.*¥+//'<<<"%h")":%p "$(sed -E 's/¥+[^¥+]*//'<<<"%h")" StrictHostKeyChecking no # ssh hoge.com/192.168.x.x #会社gateway+自席サーバ # ssh hoge.com+192.168.x.x #会社gateway/自席サーバ
これから:-J openssh-7.3 以降 # ssh -J hoge.com 192.168.x.x #会社sshgateway 会社サーバ
Configなしでやれる! 参考: https://qiita.com/kawaz/items/a0151d3aa2b6f9c4b3b8
温故知新:ワイルドカードマッチ .ssh/config: Host desk01* HostName 192.168.x.x Host desk02* HostName 192.168.x.x
ProxyCommand=ssh -W %h:%p sshgateway Match originalhost *-ofwd dynamicForward 8080 LocalForward 65422 localhost:22 $ ssh desk01-ofwd #直接接続 $ ssh desk02-ofwd #外部接続、shellscript 等で順番にtryする等でより省力化、高度化 詳細は実用SSH 第二版 P288 多重マッチ
さて • 「SSHのgatewayサーバやVPNサーバなんてうちの会社には準 備されてないよ!」
そんなあなたにautossh • autosshとは • sshクライアントを自動起動するプログラム • https://packages.debian.org/buster/autossh • リモートのsshサーバに(リバース: -R)ポートフォワード等が可能
• 後述のデフォルト設定はローカルフォワード(-L)なので書き換える • リバースポートフォワードで自宅サーバをssh踏み台に! • 使用例 • 会社サーバ(autossh)から自宅サーバ(sshd)に接続することにより自宅サーバポート に会社サーバのsshportへ転送するportを作ることができる • 自宅サーバにDDNS等でsshアクセスできれば、会社サーバはNAT下でもOK • セキュリティ • sshdのデフォルトは自宅サーバのlocalloopbackのみ許可(GatewayPorts=no)なので 使用時は自宅サーバからssh clientで接続 (つまり踏み台) • デフォルト(GatewayPorts=no)ではパブリック(0.0.0.0)には公開されていない • 御社のセキュリティ要件はご確認ください! • At your own risk. 自宅サーバ 会社サーバ sshdport へ転送 会社サーバ 作業PC ssh client sshd sshd autossh
さらにautosshをsystemdでサービス化し てssh接続を安定化 • https://remoteroom.jp/diary/2019-07-18/ • https://gist.github.com/ttimasdf/ef739670ac5d627981c5695 adf4c8f98 • 要両サーバのroot •
相互にssh専用ユーザを作成してポートフォワード専用にする • systemd設定 • autosshの死亡時に自動で再開 • 会社サーバの再起動時に自動で再開 • 安定性向上!
構成 • NAT下にある会社PC • sshdが動いていること • systemdが動いていること • sshで自宅サーバに接続できること •
rootを持っていること • (DDNS等で)インターネットからsshアクセス出来る自宅サーバ • sshdが動いていること • rootを持っていること • 自宅サーバにアクセス出来る作業用PC(自宅サーバと同じでも よい) • sshクライアントが動いていること 自宅サーバ 会社サーバ sshdport へ転送 会社サーバ 作業PC ssh client sshd sshd autossh
手順 • systemdひな形取得 • curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/autossh@host1 | ¥ •
sudo tee /etc/default/autossh@example • curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/
[email protected]
| ¥ • sudo tee /etc/systemd/system/
[email protected]
• 専用ユーザ作成(自宅サーバ、会社サーバ両方)、公開鍵作成、ssh接続 • sudo useradd -g nogroup -s /bin/false -m tunnel • sudo -u tunnel mkdir -p ~tunnel/.ssh • sudo -u tunnel nano ~tunnel/.ssh/config • sudo -u tunnel ssh remote.example.com #自宅サーバ • (設定ファイル名変更:オプション) • cp /etc/default/autossh@example /etc/default/autossh@hoge • 設定変更 • sudo nano /etc/default/autossh@example • /etc/default/autossh@example内の次の2行を編集する • TARGET_HOST=remote.example.com • 接続サーバ(自宅サーバ) • FORWARDS=-R 10022:127.0.0.1:22 • -Rオプション:リバースポートフォワード 、10022(任意:自宅サーバ側の空ポート番号)、22(会社サーバでの既存sshポート番号) • 接続 • sudo systemctl start
[email protected]
• 永続化 • sudo systemctl enable
[email protected]
自宅サーバ 会社サーバ sshdport へ転送 会社サーバ 作業PC ssh client sshd sshd autossh systemd 制御監視
SSHで快適テレワーク! • 参考URL • 最強のSSH踏み台設定 • https://qiita.com/kawaz/items/a0151d3aa2b6f9c4b3b8 • autossh&systemd •
https://remoteroom.jp/diary/2019-07-18/ • https://gist.github.com/ttimasdf/ef739670ac5d627981c5695adf4c8f 98