Connect to Linux VMs Stay organized with collections Save and categorize content based on your preferences.
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
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud 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 Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
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:
- In the Google Cloud console, go to theVM instances page.
- In the list of virtual machine instances, clickSSH in the row of the instance that you want to connect to.

gcloud
Connect to a VM using SSH by running thegcloud compute ssh command:
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 VMZONE: the name of the zone that the VM is located inVM_NAME: the name of the VM
If you haveset default properties for the Google Cloud CLI, you can omit the
--projectand--zoneflags from this command. For example:gcloud compute sshVM_NAME
In the Google Cloud console, 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.
OpenSSH client
Connect to a VM using SSH from an OpenSSH client, do the following:
- Add an SSH key to the VM if you haven't already.
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.
- Open a terminal on your workstation.
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_comorcloudysanfrancisco.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:
- Add an SSH key to the VM if you haven't already.
- If your workstation doesn't already have the PuTTY app installed,download the PuTTY package files.
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.
- Open the PuTTY app. A connection configuration window opens.
In the
Host Namefield, 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_comorcloudysanfrancisco.EXTERNAL_IP: the external IP address of the VM.
- In theCategory menu, navigate toConnection > SSH > Auth.
- In thePrivate key file for authentication field, select the private SSH key file that corresponds to the public key you added to the VM.
- 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:
Add an SSH key to the VM if youhaven't already.
InstallSecure Shell on your Chromebook or Chrome browser if you have not done so already.
In the Google Cloud console, go to theVM Instances page andfind the external IP address of the VM that you want to connectto.
Open the Secure Shell in a Chrome browser tab address bar, by doing thefollowing:
- Type
ssh. - Press
Space. - Press
Enter.
- Type
Click[New Connection].
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_comorcloudysanfrancisco.In thehostname field, enter the external IP address of the VM.
In theIdentity field, clickImport... and select the path tothe private SSH key file that corresponds to the public key you added tothe VM.
Click[ENTER] Connect to connect to the VM.
Troubleshooting
To find methods for diagnosing and resolving failed SSH connections, seeTroubleshooting SSH.
What's next
- Learn how tomanage access to VMs.
- Learn how totransfer files to VMs.
- Learn howSSH connections to Linux VMs work onCompute Engine.
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.