How to Connect to Google Cloud VM Using SSH from macOS Terminal (Full Guide)
Open your macOS terminal and run:
ssh-keygen -t rsa -f ~/Desktop/gcp/gcp
This will create:
Private key → ~/Desktop/gcp/gcp
Public key → ~/Desktop/gcp/gcp.pub
Go to:
Google Cloud Console → Compute Engine → Metadata → SSH Keys → Add Key
Paste the entire content of your gcp.pub file, which looks like:
ssh-rsa AAAAB3Nza... spotbreaks
⚠️ Note: The username at the end (e.g., spotbreaks) determines the SSH username you’ll use to connect.
Run:
ssh -i ~/Desktop/gcp/gcp spotbreaks@YOUR_VM_IP
Replace YOUR_VM_IP with your external VM IP.
If you see a welcome message — congrats, you’re in!
Add a shortcut in your SSH config file:
nano ~/.ssh/config
Then paste:
Host gcp-vm
HostName 34.118.000.00
User spotbreaks
IdentityFile ~/Desktop/gcp/gcp
Save and exit (CTRL + X, then Y).
Now connect with:
ssh gcp-vm
Boom — passwordless, clean, and fast.
Keep your private key secure — never share it.
Use VS Code Remote SSH for development inside the VM.
You can reuse the same SSH key for multiple GCP instances.
Subscribe to my newsletter to receive updates on new blog posts, tech insights, and development tips.
No spam. Unsubscribe at any time. Unsubscribe