LoginSignup
11
11

More than 3 years have passed since last update.

Visual Studio CodeでGoogle Cloud Shellを開く

Last updated at Posted at 2021-03-23

VSCode の Remote Development を使って、Google の Cloud Shell に ssh で接続して開発を行う方法です。

macOS および Windows10 でそれぞれ手順が少し異なります。また、Windows10 では Cloud Shell への接続に WSL(Windows Subsystem for Linux) を使用します。1

手順

1. gcloudコマンドを準備する

Google Cloud SDK をインストールします。

macOS は通常の手順で、Window 10 は Ubuntu の手順などに従って WSL 内でインストールを行います。その後、gcloudコマンドが使えることを確認します。

2. Cloud Shell に ssh接続できることを確認する

$ gcloud cloud-shell ssh

2-1. (Windows 10のみ)~/.ssh/google_compute_engineを移動する

Cloud Shell に ssh したあと、~/.ssh/google_compute_engineに生成されている秘密鍵をWSLからWindows側の適当な場所に移動させておきます。

3. VSCode に拡張機能 「Remote - SSH」 をインストールする

4. ~/.ssh/config を編集する

下記のように設定を追加します。UserIdentityFileなど、適宜内容を書き換えること。

Mac

Host cloudshell
    ProxyCommand gcloud cloud-shell ssh --ssh-flag='-W localhost:22'
    User CloudShellのユーザー名
    IdentityFile ~/.ssh/google_compute_engine
    StrictHostKeyChecking no

Windows 10

Host cloudshell
    ProxyCommand C:\Windows\system32\wsl.exe gcloud cloud-shell ssh --ssh-flag='-W localhost:22'
    User CloudShellのユーザー名
    IdentityFile 手順2-1.で移動させたフォルダ\google_compute_engine
    StrictHostKeyChecking no

5. VSCode から Cloud Shell を開く

VSCodeの左下の青いボタンか、F1キーを押して「Remote-SSH: Connect to Host...」を選択する。

image.png

その後、「cloudshell」を選択する。

image.png

参考

動画でも使用されているStrictHostKeyCheckingUserKnownHostsFileは警告メッセージを非表示にするための設定のようです。

また、動画ではUserを記述していませんが、ローカルのユーザー名とCloud Shellのユーザー名が異なる場合に必要です。


  1. Windows版 Google Cloud SDK には ssh用ツールとしてputty.exeが同梱されており、手順4.で設定する-Wオプションが使用できないため 

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11