Connect to Linux VMs using Identity-Aware Proxy

Linux

This document describes how to connect to a virtual machine (VM) instancethrough its internal IP address, usingIdentity-Aware Proxy (IAP) TCP forwarding.

IAP TCP forwarding lets you establish an encrypted tunnelover which you can forward SSH connections to VMs. When you connect to a VMthat uses IAP, IAP wraps the SSH connectioninside HTTPS before forwarding the connection to the VM. Then,IAP checks if you have therequired IAM permissionsand if you do, grants access to the VM.

If you need to connect to a VM that doesn't have external IP addresses and youcan't use IAP, review the other methods listed inConnection options for internal-only VMs.

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.

Permissions required for this task

To perform this task, you must have the followingpermissions:

Console

Tunnel SSH connections through a VM's internal IP address usingSSH-in-Browser by doing the following:

Note: SSH-in-Browser only uses IAP if the VM doesn't havean external IP address.

  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.

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

Tunnel SSH connections through a VM's internal IP address using thegcloud compute ssh command with the--tunnel-through-iap flag:

    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. Connect to the VM by running the following command:

    gcloud compute sshVM-NAME \    --tunnel-through-iap
  2. ReplaceVM_NAME with the name of the VM that you want to connect to.

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.

IAP Desktop

To connect to a VM using IAP Desktop, do the following:

  1. Install IAP Desktop on your workstation if you haven't already.

  2. Open IAP Desktop. TheAdd projects window opens.

  3. When prompted, sign in using the Google account that has access to the project with the VMs you want to connect to.

  4. In theAdd projects window, enter the project ID or name of the project that contains the VMs you want to connect to.

  5. In theProject Explorer window, right-click the name of the VM again and selectConnect to connect to the VM.

PuTTY app

Tunnel SSH connections through a VM's internal IP address using PuTTY, 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 name 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 name of the VM that you want to connect to. Use the following format:

    USERNAME@VM_NAME

    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.
    • NAME: the name 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. In theCategory menu, navigate toConnection > Proxy.
  9. In theProxy type section, selectLocal.
  10. In theTelnet command, or local proxy command field, enter the following command:

    gcloud.cmd compute start-iap-tunnelVM_NAMEPORT_NUMBER --listen-on-stdin --project=PROJECT_ID --zone=ZONE

    Replace the following:

    • VM_NAME: the name of the VM that you want to connect to.
    • PORT_NUMBER: the port that the sshd daemon runs on. The defaultPORT_NUMBER is22.
    • PROJECT_ID: the project that hosts the VM that you want to connect to.
    • ZONE: the zone where the VM is located.
  11. ClickOpen 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.