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
81
AlmaLinux国内、日本語サポートについて
koedoyoshida
0
220
OSC仙台プレ勉強会 AlmaLinuxとは
koedoyoshida
0
340
AlmaLinuxのセキュリティ機能評価と認証~FIPS140 3認証、CC認証 取得への取り組み~
koedoyoshida
0
130
AlmaLinux + KVM + Cockpit で始めるお手軽仮想化基盤 ~ 開発環境などでの利用を想定して ~
koedoyoshida
1
1.5k
DebConf25参加報告
koedoyoshida
0
67
AlmaLinux Users Meetup 2025 Summer / AlmaLinuxの活動
koedoyoshida
0
220
CentOS後継!業務システムで使えるAlmaLinux for Enterprise
koedoyoshida
0
370
AlmaLinux Users Meetup 2025 Summer / サイバートラストのAlmaLinuxへの取り組み
koedoyoshida
0
220
Other Decks in Technology
See All in Technology
Getting Started with Google Antigravity
glaforge
0
320
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
490
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
1
200
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
200
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
930
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
340
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
820
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
170
WasmをRustにする
sansantech
PRO
0
260
USB PDを使ってスマホを労わりたい
raspython3
0
180
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
180
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
Site-Speed That Sticks
csswizardry
13
1.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
Are puppies a ranking factor?
jonoalderson
2
4.1k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
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