Previously, I discussed what Google Cloud Shell is and how you can securely connect to it using SSH in this article:

👉 Google Cloud Shell: Establishing Secure Connections with SSH

Now, let’s take it a step further. In this post, I'll show you how to connect to your Google Cloud Shell from VS Code using SSH. This is extremely handy if you want the power of Google Cloud Shell inside VS Code.

🔧 Prerequisites

To complete this setup, make sure you have the following installed:

  1. VS Code
  2. Google Cloud CLI (gcloud)
  3. SSH installed on your machine (most Linux/macOS systems already have this)
  4. The following VS Code extensions:
    • Remote Explorer
    • Remote - SSH

🛠️ Step-by-Step Guide

1. Log in to Google Cloud

Open your terminal and run:

gcloud auth login

This will open a browser window. Log in with your Google Cloud credentials.

2. Get the SSH Connection Details

Run the following command in the terminal:

gcloud cloud-shell ssh --dry-run

This will not actually connect, but instead print out the full SSH command Google would use. You will see something like this:

ssh -i /home/mugdho/.ssh/google_cloud_key -p 6000 mugdho@34.57.128.215

From this, take note of:

  • Username
  • Host/IP (eg:34.57.128.215)
  • Port (eg: 6000)
  • Private key path (eg: /home/mugdho/.ssh/google_cloud_key)

3. Configure SSH for Google Cloud Shell

Open your SSH config file using:

nano ~/.ssh/config

Or if you prefer VS Code:

code ~/.ssh/config

Then add the following block (replace placeholders with your actual values):

Host google-cloud-shell
  HostName 
  User 
  Port >
  IdentityFile 
  StrictHostKeyChecking no

Save and close the file.

4. Open VS Code and Use Remote Explorer

  1. Launch VS Code
  2. On the left sidebar, click on the Remote Explorer icon.
  3. Under the "SSH Targets" section, hover and click the ‘+’ icon.

New Remote

  1. A text input bar will appear at the top. Enter your connection string:
username@hostname

ssh address

Press Enter. VS Code will now recognize this SSH target.

5. Connect to Google Cloud Shell

Now under the SSH section in Remote Explorer, you’ll see your saved target (e.g., google-cloud-shell).

Click the ➜ (arrow) button beside it to connect.

google-cloud-shell

You’re now connected to Google Cloud Shell right inside VS Code! 🎉

To disconnect, click on the blue button in the bottom-left corner of VS Code.

Remote SSH Button

Then click on Close Remote Connection.

Close Remote Connection

The connection will be closed.

Thanks for reading