Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
sshで快適テレワーク
Search
koedoyoshida
March 28, 2020
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
sshで快適テレワーク
今まで:最強のSSH踏み台設定
これから:-J
温故知新:ワイルドカードマッチ
自宅サーバ活用:autossh&systemd
koedoyoshida
March 28, 2020
More Decks by koedoyoshida
See All by koedoyoshida
AlmaLinuxの最新動向と、企業の多種多様なLinux環境を保護する「安心サポート」活用術
koedoyoshida
0
62
AlmaLinux国内、日本語サポートについて
koedoyoshida
0
200
OSC仙台プレ勉強会 AlmaLinuxとは
koedoyoshida
0
320
AlmaLinuxのセキュリティ機能評価と認証~FIPS140 3認証、CC認証 取得への取り組み~
koedoyoshida
0
110
AlmaLinux + KVM + Cockpit で始めるお手軽仮想化基盤 ~ 開発環境などでの利用を想定して ~
koedoyoshida
1
1.4k
DebConf25参加報告
koedoyoshida
0
64
AlmaLinux Users Meetup 2025 Summer / AlmaLinuxの活動
koedoyoshida
0
210
CentOS後継!業務システムで使えるAlmaLinux for Enterprise
koedoyoshida
0
340
AlmaLinux Users Meetup 2025 Summer / サイバートラストのAlmaLinuxへの取り組み
koedoyoshida
0
220
Other Decks in Technology
See All in Technology
おい、エージェントを使って終わらせろ
nwiizo
0
290
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
740
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
1.9k
LTのテーマ どうきめてる?〜5つの型と私のやり方〜
yama3133
1
110
AI時代、データエンジニアが一番おもろい
genshun9
0
610
20260912_スクラムにジェネラリストは必要か
ryugen04
0
420
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
150
iOSDC Japan 2026 day1 TrackC 10:50
feedtailor
1
160
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
8
950
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
3
510
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
2
600
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
22
14k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Believing is Seeing
oripsolob
1
220
Are puppies a ranking factor?
jonoalderson
2
3.9k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
330
Raft: Consensus for Rubyists
vanstee
142
7.7k
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