Connecting to Linux VMs using the Cloud Console and the gcloud tool

This document describes how to connect to Linux virtual machine (VM) instances using the Google Cloud Console and the gcloud command-line tool. For other ways to connect to Linux VMs, such as using third-party tools including PuTTY, see Connecting to VMs using advanced methods.

Before you begin

Connecting to VMs

  • For information about how SSH connections work in Compute Engine, including SSH key configuration and storage, see SSH connections to Linux VMs.

To connect to Linux instances through the Google Cloud Console or the gcloud command-line tool, complete the steps in one of the following tabs.


  1. In the Cloud Console, go to the VM instances page.

    Go to VM instances

  2. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

    SSH button next to instance name.


Use the gcloud compute ssh command to connect to instances that you have permission to access:

gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME

Replace the following:

  • PROJECT_ID: the ID of the project that contains the instance
  • ZONE: the name of the zone in which the instance is located
  • VM_NAME: the name of the instance

If you have set default properties for the gcloud command-line tool, you can omit the --project and --zone flags from this command. For example:

gcloud compute ssh VM_NAME

After you connect, use the terminal to run commands on your Linux instance. When you have finished, disconnect from the instance by using the exit command.

Where SSH keys are stored

When you connect to a VM instance for the first time, Compute Engine generates an SSH key pair for you and stores it in one of the following locations:

  • By default, Compute Engine adds the generated key pair to project or instance metadata.
  • If your account is configured to use OS Login, Compute Engine stores the generated key pair with your user account.

You do not need to know where your SSH key pairs are stored if you're connecting in the ways described in this document, but you might need to know where your SSH key pairs are stored if you want to connect using the advanced methods.

What's next