Prerequisites
Before we begin, ensure you have the following tools installed:
- Google Cloud CLI (gcloud) - Essential for managing Google Cloud resources from the command line.
- VSCode Remote - SSH Extension - This extension allows VSCode to connect to remote machines using SSH.
Step-by-Step Instructions
Updating SSH Configuration
First, we need to update the SSH configuration to include the Google Cloud Compute (GCE) instance. This involves setting a ProxyCommand to facilitate the connection. Here’s how you do it:
- Open your SSH config file (usually found at
~/.ssh/config
). - Add the following configuration for your GCE instance:
Host my-gce-instance-name
HostName my-gce-instance-name
User your_username
ProxyCommand gcloud compute ssh %r@%h -- -W %h:%p
Replace my-gce-instance-name
with your instance name and your_username
with your GCE username.
Note: The ProxyCommand
might require adjustments based on your setup. For instance, specify the --zone
flag if you haven’t set a default zone in gcloud. Basically you should use ther same args you would use when connecting directly using gcloud compute ssh
normally.
Refer to the gcloud compute ssh documentation for detailed information.
Connecting via VSCode
With your SSH config updated, you can now connect to your GCE instance using VSCode:
- Launch VSCode.
- Open the
Remote Explorer
from the left sidebar. - In the
Remote Explorer
panel, selectRemotes (SSH/Tunnels)
from the dropdown menu at the top. - Expand the
SSH
section. You should see theHost
you defined in your SSH config. - Click on the defined
Host
to establish a connection.
And that’s it! You’re now connected to your GCE instance through VSCode, ready to work remotely with the power of cloud computing at your fingertips.