Connect to Linux VMs

Linux

This document describes how to connect to Linux virtual machine (VM) instancesthat have external IP addresses by using SSH keys. To learn how to connect toVMs that don't have external IP addresses, seeConnection options for internal-only VMs.To learn how to connect to Linux VMs using SSH certificates, seeRequire SSH certificates for OS Login VMs.

For information abouthow SSH connections work in Compute Engine, including SSH key configurationand storage, seeSSH connections to Linux VMs.

Note: When a user connects to a VM, that user can use all of the IAM permissions granted to the service account attached to the VM.

Before you begin

Supported operating systems

These connection methods are supported for allpublic Linux images that are available onCompute Engine. For Fedora CoreOS images, you mustset 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

Connect to VMs usingSSH-in-browser from theGoogle Cloud console, by doing the following:

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

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

    SSH button next to instance name.

Note: When you connect to VMs using the Google Cloud console,Compute Engine creates an ephemeral SSH key for you. For more informationabout SSH keys, seeSSH connections to Linux VMs.

gcloud

Connect to a VM using SSH by running thegcloud compute ssh command:

    In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, aCloud 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.

  1. Run the following command:

    gcloud compute ssh --project=PROJECT_ID --zone=ZONEVM_NAME

    Replace the following:

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

    If you haveset default properties for the Google Cloud CLI, you can omit the--project and--zone flags from this command. For example:

    gcloud compute sshVM_NAME
Note: When you connect to VMs using the gcloud CLI, Compute Engine creates a persistent SSH key for you. For more information about SSH keys, seeSSH connections to Linux VMs.

OpenSSH client

Connect to a VM using SSH from an OpenSSH client, do the following:

  1. Add an SSH key to the VM if you haven't already.
  2. In the Google Cloud console, go to theVM Instances page and find the external IP address of the VM that you want to connect to.

    Go to VM Instances

  3. Open a terminal on your workstation.
  4. Connect to the VM by running the following command:

    ssh -iPATH_TO_PRIVATE_KEYUSERNAME@EXTERNAL_IP

    Replace the following:

    • PATH_TO_PRIVATE_KEY: the path to the private SSH key file that corresponds to the public key you added to the VM.
    • USERNAME: your username. If you manage your SSH keys in metadata, the username is what you specified when youcreated the SSH key. For OS Login accounts, the username isdefined in your Google profile. For example,cloudysanfrancisco_example_com orcloudysanfrancisco.
    • EXTERNAL_IP: the external IP address of the VM.

PuTTY app

Connect to a VM using SSH from the Windows PuTTY app, by doing the following:

  1. Add an SSH key to the VM if you haven't already.
  2. If your workstation doesn't already have the PuTTY app installed,download the PuTTY package files.
  3. In the Google Cloud console, go to theVM Instances page and find the external IP address of the VM that you want to connect to.

    Go to VM Instances

  4. Open the PuTTY app. A connection configuration window opens.
  5. In theHost Name 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: your username. If you manage your SSH keys in metadata, the username is what you specified when youcreated the SSH key. For OS Login accounts, the username isdefined in your Google profile. For example,cloudysanfrancisco_example_com orcloudysanfrancisco.
    • EXTERNAL_IP: the external IP address of the VM.
  6. In theCategory menu, navigate toConnection > SSH > Auth.
  7. In thePrivate key file for authentication field, select the private SSH key file that corresponds to the public key you added to the VM.
  8. ClickOpen to connect to the VM.

Secure Shell Chrome app

To connect to a VM using SSH from the Secure Shell Chrome app, do thefollowing:

  1. Add an SSH key to the VM if youhaven't already.

  2. InstallSecure Shell on your Chromebook or Chrome browser if you have not done so already.

  3. In the Google Cloud console, go to theVM Instances page andfind the external IP address of the VM that you want to connectto.

    Go to VM Instances

  4. Open the Secure Shell in a Chrome browser tab address bar, by doing thefollowing:

    • Typessh.
    • PressSpace.
    • PressEnter.
  5. Click[New Connection].

  6. In theusername field, enter your username. If you manage your SSHkeys in metadata, the username is what you specified when youcreated the SSH key. For OSLogin accounts, the username isdefined in your Google profile.For example,cloudysanfrancisco_example_com orcloudysanfrancisco.

  7. In thehostname field, enter the external IP address of the VM.

  8. In theIdentity field, clickImport... and select the path tothe private SSH key file that corresponds to the public key you added tothe VM.

  9. Click[ENTER] Connect to connect to the VM.

Troubleshooting

To find methods for diagnosing and resolving failed SSH connections, seeTroubleshooting SSH.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.