You can use the Google Cloud browser terminal or connect from your own computer. You do not need to install an SSH server, find the VM’s IP address, or configure mDNS.
In this guide:
[local].This is the simplest method and requires no local setup.
The course VM has no external IP address, so local SSH must use an Identity-Aware Proxy (IAP) tunnel.
Authenticate and select your project:
[local] gcloud init
[local] gcloud config set project PROJECT_ID
Connect:
[local] gcloud compute ssh INSTANCE_NAME --zone=ZONE --tunnel-through-iap
Replace PROJECT_ID, INSTANCE_NAME, and ZONE with your values.
Do not install
openssh-server, assign an external IP, or open SSH to the internet. GCP already prepares the VM for SSH, and IAP provides the private connection.
Create a separate SSH key on the VM. Do not copy your private key from your local computer or enable SSH agent forwarding.
Generate a key:
ssh-keygen -t ed25519 -C "YOUR_EMAIL"
Press Enter to accept the default filename. You may add a passphrase or leave it empty.
Display the public key:
cat ~/.ssh/id_ed25519.pub
Test the connection:
ssh -T git@github.com
If GitHub greets you by username, the setup is complete.
Never share or copy
~/.ssh/id_ed25519. Only~/.ssh/id_ed25519.pubis public.
gcloud compute ssh command above at least once. This creates and registers the local SSH key used by GCP.Generate the exact underlying SSH command:
[local] gcloud compute ssh INSTANCE_NAME --zone=ZONE --tunnel-through-iap --dry-run
Use the values from that output to add an entry to your local ~/.ssh/config. A typical entry is:
Host osvm
HostName INSTANCE_NAME
User GCP_USERNAME
IdentityFile ~/.ssh/google_compute_engine
ProxyCommand gcloud compute start-iap-tunnel %h 22 --listen-on-stdin --project=PROJECT_ID --zone=ZONE
Run whoami on the VM to find GCP_USERNAME.
Test the configuration:
[local] ssh osvm
--dry-run command and use the exact username, key path, and proxy command it displays.