vast.aiのインスタンスにsshで接続する
公式の解説はこちら
https://docs.vast.ai/instances/sshscp
まずはssh keyの登録(公開鍵)
アカウントを選択して
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
SSH Keysをクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
入力したら自動的に保存される。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
もしすでにインスタンスが起動中であれば、一度停止して再度起動します。
接続先
インスタンスを起動したらここをクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
接続方法が出てくるのでコピーしておく。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ターミナルで実行すると繋がりました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ちなみに、Open Jupyter terminalを押すとブラウザ経由でJupyterが扱えるみたい
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
vscodeでssh接続してファイルを扱えるようにする
下記をクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ホストに接続するをクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
新規SSHホストを追加する
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
sshコマンドを貼り付け
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
繋がりました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
次に、ディレクトリの共有もしたいので
フォルダを開くをクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
開きたいパスのところを入力します。今回はリモートにある/workspaceです。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
信頼する。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ディレクトリも共有されました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ポートフォワーディングしてlocalhostからアクセスできるようにする
ssh -p 30829 root@58.224.7.136 -L 8080:localhost:8080
こちらの-L 11434:localhost:11434でポートフォワーディングがされています。
こちらをインスタンスのポートと対応付ければlocalhost経由で接続できるようになります。
これらを同じように対応付ける感じです。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
各ポートが何を表しているかは、WebUiから確認できました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
設定は以下でします。
再度ホストに接続するをクリックします。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ホストを構成するをクリック
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
以下のようにポートフォワーディングの設定を追加します。
Host 58.224.7.136
HostName 58.224.7.136
Port 30829
User root
LocalForward 8080 localhost:8080
LocalForward 11434 localhost:11434
LocalForward 7500 localhost:7500
postmanで動作確認するとうまくいくことが確認できました。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
webuiの方も接続できることを確認
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
おまけ
それ以外にも、データ保存のためにCloud Connectionを使ったり、インスタンス起動時に環境変数をインジェクトしてくれるEnvironment Variablesは触っておいて損ないと思います。
![](http://takumi-oda.com/blog/wp-content/themes/luxeritas/images/trans.png)
ディスカッション
コメント一覧
まだ、コメントがありません