How to SSH into Google Cloud Compute Engine
Google Cloud Platform Compute Engine VM. Learn how to securely connect to your server from any browser without installing native terminal apps like PuTTY or Termius.
Connection Quick Reference
- Default Username:YOUR_GCP_USERNAME
- Authentication:SSH Key
OS Login vs. Metadata SSH Keys
Google Cloud Platform (GCP) handles SSH authentication quite differently from traditional Linux distributions. By default, Compute Engine instances use either OS Login or Metadata-based SSH keys.
OS Login (The Modern Standard)
If OS Login is enabled (which is the recommended best practice for enterprise environments), GCP manages your SSH keys entirely through IAM (Identity and Access Management). In this scenario, you cannot simply append a public key to ~/.ssh/authorized_keys, because the system explicitly ignores that file.
Instead, you must add your public SSH key to your Google account or the project metadata via the gcloud CLI or the Google Cloud Console. GCP will dynamically provision a user account for you on the VM based on your Google email address (e.g., if your email is admin@example.com, your OS Login username is typically admin_example_com).
Metadata-based Keys (The Legacy Method)
If OS Login is disabled, GCP uses a custom daemon that continuously polls the instance's metadata server. If you add a public SSH key to the instance (or project) metadata, this daemon automatically creates a local Linux user account and populates their .ssh/authorized_keys file on the fly.
To use SSHDock with GCP, you must manually inject your public key into the metadata, and then connect using the username you specified when generating the key pair.
Finding Your External IP Address
Compute Engine VMs in GCP can have both internal and external IP addresses. You must use the External IP to connect via SSHDock.
- Navigate to the Google Cloud Console.
- Go to Compute Engine > VM instances.
- In the list of your instances, look at the External IP column.
- Copy this IP address. Note that unless you reserved a static external IP, this IP will change if you stop and start the instance.
Connecting with SSHDock
Since GCP doesn't hand you a .pem file on a silver platter like AWS, the easiest way to connect via SSHDock is to generate a new key pair locally (or within SSHDock), and add the public key to GCP.
Step 1: Generate or Locate Your Keys
If you don't already have an SSH key pair, you can use the standard ssh-keygen command on your local machine to generate one. The public key (e.g., id_rsa.pub) goes to Google, and the private key (e.g., id_rsa) goes into SSHDock.
Step 2: Add the Public Key to GCP Metadata
- In the GCP Console, click on your VM instance.
- Click the Edit button at the top.
- Scroll down to the Security and Access section and find SSH Keys.
- Click Add Item.
- Paste the entire contents of your public key. The text box will automatically extract the username from the end of the public key string (e.g.,
ssh-rsa AAAAB3... user@machinewill extract the usernameuser). - Save the changes. GCP will immediately provision that user on the VM.
Step 3: Connect via SSHDock
- Open SSHDock.
- Enter the External IP of your GCP instance.
- Enter the exact Username that GCP extracted from your public key in the previous step.
- Select Private Key authentication.
- Paste your private key (the file without the
.pubextension) into SSHDock. - Click Connect.
Troubleshooting GCP Connections
Connection Timed Out
Google Cloud firewall rules (VPC firewall) operate independently of iptables inside the VM.
- Go to VPC network > Firewall.
- Ensure there is an ingress rule allowing TCP port 22 traffic from
0.0.0.0/0(or your specific IP) targeting your instance (often managed via Network Tags likeallow-ssh).
Permission Denied (publickey)
If you get a permission denied error, the GCP metadata daemon likely rejected your key or hasn't processed it yet.
- Ensure you are using the exact username that is tied to the key in the metadata.
- Check if OS Login is enabled. If it is, metadata keys will be ignored, and you must use the
gcloud compute os-login ssh-keys addcommand to upload your key instead.