This document describes how to connect to Linux virtual machine (VM) instances that have external IP addresses by using SSH. To connect to VMs that don't have external IP addresses, see Choose a connection option for internal-only VMs. To connect to Linux VMs by using SSH certificates, see Require SSH certificates for OS Login VMs.
For information about how SSH connections work in Compute Engine, including SSH key configuration and storage, see SSH connections to Linux VMs.
Before you begin
- Configure a firewall rule,
such as the
default-allow-sshrule, in the Virtual Private Cloud (VPC) network for your VM to allow ingress TCP traffic on port22. - Configure SSH access on the VM by using either OS Login (recommended) or metadata-based SSH keys, and grant the required Identity and Access Management (IAM) roles for your chosen method. If you connect by using the Cloud de Confiance console or the Google Cloud CLI, Compute Engine manages SSH keys for you.
-
If you haven't already, set up authentication.
Authentication verifies your identity for access to Cloud de Confiance by S3NS services and APIs. To run
code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Cloud de Confiance console to access Cloud de Confiance by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity. After signing in, initialize the Google Cloud CLI by running the following command:
gcloud init - Set a default region and zone.
-
Supported operating systems
Compute Engine supports these connection methods for all public Linux images. For Fedora CoreOS images, you must set up SSH access before you can use these methods.
Connect to VMs
To connect to a VM, complete the steps in one of the following tabs.
Console
To connect to a VM by using SSH-in-browser from the Cloud de Confiance console, do the following:
- In the Cloud de Confiance console, go to the VM instances page.
-
In the list of virtual machine instances, click SSH in the row of
the instance that you want to connect to.

gcloud
Connect to a VM by using SSH and by running the
gcloud compute ssh
command:
-
In the Cloud de Confiance console, activate Cloud Shell.
At the bottom of the Cloud de Confiance console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Run the following command:
gcloud compute ssh INSTANCE_NAME \ --project=PROJECT_ID \ --zone=ZONEReplace the following:
INSTANCE_NAME: the name of the VM.PROJECT_ID: the ID of the project that contains the VM.ZONE: the name of the zone that the VM is located in.
If you have set default properties for the Google Cloud CLI, you can omit the
--projectand--zoneflags from this command. For example:gcloud compute ssh INSTANCE_NAME
OpenSSH client
To connect to a VM by using SSH from an OpenSSH client, do the following:
- If you haven't already added an SSH key, add an SSH key to the VM.
In the Cloud de Confiance console, go to the VM instances page and find the external IP address of the VM that you want to connect to.
- Open a terminal on your workstation.
Connect to the VM by running the following command:
ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP
Replace the following:
PATH_TO_PRIVATE_KEY: the path to the private SSH key file that corresponds to the public key that you added to the VM, such as~/.ssh/my-ssh-key, or~/.ssh/google_compute_engineif the Google Cloud CLI generated the key.USERNAME: the username is what you specified when you created the SSH key.-
EXTERNAL_IP: the external IP address of the VM.
PuTTY app
To connect to a VM by using SSH from the Windows PuTTY app, do the following:
- If you haven't already added an SSH key, add an SSH key to the VM.
- If your workstation doesn't already have the PuTTY app installed, download the PuTTY package files.
In the Cloud de Confiance console, go to the VM instances page and find the external IP address of the VM that you want to connect to.
- Open the PuTTY app. A connection configuration window opens.
In the Host Name (or IP address) field, enter the username associated with the SSH key and the external IP address of the VM that you want to connect to. Use the following format:
USERNAME@EXTERNAL_IP
Replace the following:
USERNAME: the username is what you specified when you created the SSH key.-
EXTERNAL_IP: the external IP address of the VM.
- In the Category menu, go to Connection > SSH > Auth > Credentials (or Connection > SSH > Auth in PuTTY versions earlier than 0.78).
- In the Private key file for authentication field, click
Browse and select the private SSH key file
(
.ppk) that corresponds to the public key that you added to the VM. - Click Open to connect to the VM.
What's next
Learn how to manage access to VMs.
Learn how to transfer files to VMs.
Learn how SSH connections to Linux VMs work on Compute Engine.