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
Colabをshellから使う
Search
SATOH Kiyoshi
March 22, 2022
Technology
0
120
Colabをshellから使う
2019/08/10のNSEG勉強会で話した内容です。
Colab上でshellを使う手法の紹介と、自サーバへのリモートフォワードで使う方法を説明します。
SATOH Kiyoshi
March 22, 2022
Tweet
Share
More Decks by SATOH Kiyoshi
See All by SATOH Kiyoshi
意外に詐欺師がいるという教訓
stealthinu
0
100
RAGの仕組みとよくある課題
stealthinu
1
730
音声変換と生成AI:開発者視点からの1.5年の振り返り
stealthinu
0
1.3k
リアルタイムボイスチェンジャーMMVCとVITSの紹介
stealthinu
0
2.6k
ディープラーニングブームは続くのか
stealthinu
0
95
スパム対策お焚き上げ
stealthinu
0
89
えせソアリンを作る
stealthinu
0
110
milter-managerが便利な話
stealthinu
0
160
GCEをTensorFlowの「計算エンジン」にする
stealthinu
0
93
Other Decks in Technology
See All in Technology
エンジニアのためのドキュメント力基礎講座〜構造化思考から始めよう〜(2025/02/15jbug広島#15発表資料)
yasuoyasuo
15
5.5k
MC906491 を見据えた Microsoft Entra Connect アップグレード対応
tamaiyutaro
1
480
All you need to know about InnoDB Primary Keys
lefred
0
120
2.5Dモデルのすべて
yu4u
2
610
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
6
1.4k
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
5.1k
これからSREになる人と、これからもSREをやっていく人へ
masayoshi
6
4.1k
5分で紹介する生成AIエージェントとAmazon Bedrock Agents / 5-minutes introduction to generative AI agents and Amazon Bedrock Agents
hideakiaoyagi
0
220
君はPostScriptなウィンドウシステム 「NeWS」をご存知か?/sunnews
koyhoge
0
720
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
770
開発者が自律的に AWS Security Hub findings に 対応する仕組みと AWS re:Invent 2024 登壇体験談 / Developers autonomously report AWS Security Hub findings Corresponding mechanism and AWS re:Invent 2024 presentation experience
kaminashi
0
190
室長と気ままに学ぶマイクロソフトのビジネスアプリケーションとビジネスプロセス
ryoheig0405
0
320
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Documentation Writing (for coders)
carmenintech
67
4.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
The Cult of Friendly URLs
andyhume
78
6.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
How GitHub (no longer) Works
holman
313
140k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
We Have a Design System, Now What?
morganepeng
51
7.4k
Transcript
Colab をshell から使う Colab をshell から使う 2019/8/10 さとうきよし
Colab とは Colab とは 無料でGPU/TPU 付きサーバを使えるサービス Web(Jupyter) 上からPython 環境が即利⽤可能 最⾼!
Colab の構成 Colab の構成 接続時にlinux のコンテナが起動 Web(Jupyter) 上から操作を⾏う コンテナ種によりGPU かTPU
が利⽤できる 完全に独⽴した環境なのでインストールも可能 コンテナは連続12 時間までしか稼働出来ない
コマンドの実⾏ コマンドの実⾏ Python の他にコマンドも実⾏可能 !cat /etc/debian_version !apt install sshd だがセルからしか実⾏できないため結構不便
外からの接続は出来ない 外からの接続は出来ない 外には出ていけるが外からは接続できない コンテナから外にトンネルを作りそこ経由で接続
ngrok というサービス ngrok というサービス ローカル上のものを外から接続可能にするサービス テストで動かしてるWeb サービスを⼀時的に接続可に 特定サーバ・ポートにアクセスするとフォワードする serveo という同種のサービスもある
Colab からngrok を利⽤ Colab からngrok を利⽤ sshd とngrok をコマンドで⼊れて利⽤ 下記内容をセルに貼って実⾏
import random, string, urllib.request, json, getpass #Generate root password password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20)) #Download ngrok ! wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux- ! unzip -qq -n ngrok-stable-linux-amd64.zip #Setup sshd ! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null #Set root password ! echo root:$password | chpasswd ! mkdir -p /var/run/sshd ! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config ! echo "PasswordAuthentication yes" >> /etc/ssh/sshd config https://stackover ow.com/questions/48459804/how-can-i- ssh-to-google-colaboratory-vm
ngrok の問題 ngrok の問題 時々切れる ちょっと重い ngrok へのログインがだるい セキュリティ上の懸念(MITM) がちょっと不安
ssh のリモートフォワード ssh のリモートフォワード 固定IP のサーバがあればngrok と同様のことが可能 local から実⾏ ssh
-R 8081:target:80 remote /etc/ssh/sshd_con g にリモート接続許可する設定が必要 GatewayPorts yes https://qiita.com/mechamogera/items/b1bb9130273deb9426f5
Colab→ ⾃サーバへのトンネル Colab→ ⾃サーバへのトンネル Colab 側から⾃サーバへトンネルを張る ⾃サーバからトンネル伝ってssh 接続 Colab 側から実⾏
ssh -fNR 20022:target:22
[email protected]
dev.example.jp から実⾏ ssh -p 20022 root@localhost
⼊⼒が出来ない問題 ⼊⼒が出来ない問題 プロンプトからのパスワード⼊⼒等が出来ない パスワード⼊⼒はフォーム機能で⼊れる パスワード受け渡しはSSH_ASKPASS で回避 HostKeyChecking もオプションで回避 proxy_password =
'password' #@param {type:"string"} !echo "echo $proxy_password" > proxy_password.sh !chmod +x proxy_password.sh get_ipython().system_raw( 'export SSH_ASKPASS=/content/proxy_password.sh; export DISPLAY=dummy:0; setsid ssh -oStrictHostKeyChecking=no -fNR 20022:localhost:22
[email protected]
&')
Colab 側sshd の起動 Colab 側sshd の起動 先にsshd を⼊れて起動しておく LD_LIBRARY_PATH の設定無いとエラーになるので注意
import random, string, urllib.request, json, getpass password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20)) print(f'Root password: {password}') ! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null ! echo root:$password | chpasswd ! mkdir -p /var/run/sshd ! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config ! echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config ! echo "ClientAliveInterval 30" >> /etc/ssh/sshd_config ! echo "GatewayPorts yes" >> /etc/ssh/sshd_config ! echo "LD_LIBRARY_PATH=/usr/lib64-nvidia" >> /root/.bashrc ! echo "export LD_LIBRARY_PATH" >> /root/.bashrc get_ipython().system_raw('/usr/sbin/sshd -D &')
問題点 問題点 ⾃サーバがない → GCE の無料枠で踏み台サーバを⽴てる パスワードの受け渡し⽅ フォーム機能だとノートにパスワードが残る
Colab でshell 使えるの便利 Colab でshell 使えるの便利 ディープラーニングもののプロダクトの実験に便利 ⾃宅に⾼いGPU 積んだマシンなくても気軽に試せる