This document describes how to connect to Linux virtual machine (VM) instances that have external IP addresses. To learn how to connect to VMs that don't have external IP addresses, see Connection options for internal-only 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
-
If you haven't already, set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine as follows.
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, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
-
Supported operating systems
These connection methods are supported for all public Linux images that are available on Compute Engine. 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
Connect to VMs using SSH-in-Browser from the Google Cloud console, by doing the following:
- In the Google Cloud 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 using SSH by running the
gcloud compute ssh
command:
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud 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 --project=PROJECT_ID --zone=ZONE VM_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 have set default properties for the Google Cloud CLI, you can omit the
--project
and--zone
flags from this command. For example:gcloud compute ssh VM_NAME
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 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 you added to the VM.USERNAME
: your username. If you manage your SSH keys in metadata, the username is what you specified when you created the SSH key. For OS Login accounts, the username is defined 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:
- 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 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
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 you created the SSH key. For OS Login accounts, the username is defined in your Google profile. For example,cloudysanfrancisco_example_com
orcloudysanfrancisco
.-
EXTERNAL_IP
: the external IP address of the VM.
- In the Category menu, navigate to Connection > SSH > Auth.
- In the Private key file for authentication field, select the private SSH key file that corresponds to the public key you added to the VM.
- Click Open to connect to the VM.
Secure Shell Chrome app
To connect to a VM using SSH from the Secure Shell Chrome app, do the following:
Add an SSH key to the VM if you haven't already.
Install Secure Shell on your Chromebook or Chrome browser if you have not done so already.
In the Google Cloud console, go to the VM Instances page and find the external IP address of the VM that you want to connect to.
Open the Secure Shell in a Chrome browser tab address bar, by doing the following:
- Type
ssh
. - Press
Space
. - Press
Enter
.
- Type
Click [New Connection].
In the username field, enter your username. If you manage your SSH keys in metadata, the username is what you specified when you created the SSH key. For OS Login accounts, the username is defined in your Google profile. For example,
cloudysanfrancisco_example_com
orcloudysanfrancisco
.In the hostname field, enter the external IP address of the VM.
In the Identity field, click Import... and select the path to the private SSH key file that corresponds to the public key you added to the VM.
Click [ENTER] Connect to connect to the VM.
Troubleshooting
To find methods for diagnosing and resolving failed SSH connections, see Troubleshooting SSH.
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.