To SSH into your new Google Cloud VM from your Mac, you’ll need to transfer your public SSH key to the VM. Here’s how to do it step by step:
✅ 1. Check for an Existing SSH Key on Your Mac
Open Terminal on your Mac and run:
ls ~/.ssh
Look for a file like id_rsa.pub or id_ed25519.pub. If you see one, that’s your public key.
If you don’t have one, generate it:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Press Enter to accept defaults and it will create a key pair at ~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
.
✅ 2. Add Your Public Key to the Google Cloud VM
You have two options:
Option A: Use gcloud CLI (Recommended)
If you have the Google Cloud SDK installed:
gcloud compute ssh [INSTANCE_NAME] --zone=[ZONE] --project=[PROJECT_ID]
The gcloud CLI will automatically copy your public SSH key to the instance and SSH you in.
Option B: Manually Add SSH Key via Google Cloud Console
Open the Google Cloud Console.
Go to: Compute Engine > VM instances.
-
Click on your instance name.
-
Click Edit.
Scroll to the SSH Keys section.
Paste your public SSH key (contents of ~/.ssh/id_rsa.pub
) into the field.
The key should look like:
ssh-rsa AAAAB3Nza... your_email@example.com
Save changes.
✅ 3. SSH from Your Mac
Once the key is added, SSH into your VM from your Mac like this:
ssh [USERNAME]@[EXTERNAL_IP]
USERNAME: Should match the username used in your SSH key.
If you pasted the key in manually, use the name that appears at the end of the public key.
EXTERNAL_IP: Found in the VM details in the Cloud Console.
✅ Optional: Use an SSH Config File (Convenience)
Create or edit ~/.ssh/config
:
Host my-gce-vm
HostName [EXTERNAL_IP]
User [USERNAME]
IdentityFile ~/.ssh/id_rsa
Then SSH using:
ssh my-gce-vm