SSH Setup & Connection
Once your VM is up and running, there are several ways to connect. For professional development, using a local SSH key is the industry standard.
Method A: Web SSH (Easiest)
Click the SSH button next to your instance in the GCP console to open a terminal directly in your browser. This is great for quick troubleshooting.
Method B: Local SSH Key (Industry Standard)
- Generate Key: Run
ssh-keygen -t rsa -f ~/.ssh/gcp_key -C myuseron your local terminal. - Copy Public Key: Run
cat ~/.ssh/gcp_key.puband copy the output. - Bind in GCP: Go to Metadata -> SSH Keys in the GCP console and paste the key.
- Connect: Run
ssh -i ~/.ssh/gcp_key myuser@<VM_EXTERNAL_IP>.
Method C: Connect with an SSH Config Alias
Save the VM connection details in ~/.ssh/config so you can connect with a short, memorable command.
-
Make sure your public key has been added to the VM or the project's Metadata -> SSH Keys.
-
Add the following entry to
~/.ssh/config:Host YOUR_SSH_ALIAS
HostName YOUR_VM_EXTERNAL_IP
User YOUR_SSH_USERNAME
IdentityFile PATH_TO_YOUR_PRIVATE_KEY
IdentitiesOnly yesReplace each uppercase placeholder with your own connection details.
-
Restrict the file permissions:
chmod 600 ~/.ssh/configYour private key should also be readable only by your user (
chmod 600). -
Connect using the host alias:
ssh YOUR_SSH_ALIAS
If the VM uses an ephemeral external IP address, update HostName whenever the address changes. A static external IP avoids this extra step.