Connecting to Instances

Compute Engine provides tools to manage your SSH keys and help you connect to either Linux and Windows Server instances.

This page explains the most basic ways to connect to your Compute Engine instances. Alternatively, you can learn how to connect to instances using third-party tools or connect to instances that have no external IP addresses.

Before you connect to an instance, you must first set up user access to your instance. To learn how to to manage user access to your instances, see Managing Instance Access.

Connecting to Linux instances

You can connect to Linux instances through either the Google Cloud Platform Console or the gcloud command-line tool. Compute Engine generates an SSH key for you and stores it in one of the following locations:

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

Console

  1. In the GCP Console, go to the VM Instances page.

    Go to the VM Instances page

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

gcloud SDK

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

gcloud compute ssh --project [PROJECT_ID] --zone [ZONE] [INSTANCE_NAME]

Where:

  • [PROJECT_ID] is the ID of the project that contains the instance.
  • [ZONE] is the name of the zone in which the instance is located.
  • [INSTANCE_NAME] is 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 [INSTANCE_NAME]

After you connect, you can use the terminal to run commands on your Linux instance. When you are done, use the exit command to disconnect from the instance.

Connecting to Windows instances

You can connect to Windows instances via command line and graphical interfaces depending on your preference or use case. Each connection interface has multiple connection methods. Choose the method that works best for you.

Connect using a graphical interface

Connecting to Windows with the Desktop Experience allows for the most flexibility and compatibility with applications and tooling.

Console

Connecting using the Chrome RDP extension allows for flexibility between multiple operating systems and is integrated with the GCP Console for convenience.

  1. If you have not already done so, install the Chrome RDP for Google Cloud Platform extension.
  2. Open your Windows instance from the VM instances page in Cloud Console.
  3. Click the RDP button on the instance page to open the extension.
  4. Enter the domain, username and password of the instance, and click OK to connect. Screenshot of the instance creation window with the required options
   set

    If the instance does not have a domain configured, leave this field blank.

    If this is your first time connecting to this instance, or if you have forgotten your password create a new Windows instance password.

  5. If prompted, press Continue to accept the certificate.

Native (mstsc)

Connecting with the native RDP client allows for the best feature set and compatibility.

  1. Open Microsoft Windows Remote Desktop Connection on your Windows machine. Screenshot of the mstsc connection window

  2. Identify the external IP of your Windows instance from the VM instances page, or the gcloud SDK command below:

    gcloud compute instances list
    
  3. Enter the IP address into the 'Computer' field and click Connect.

    If a non-standard port number is configured for RDP on the instance, add it after the IP address. For example, 1.2.3.4:3389.

  4. Enter your username and password on the instance, and click OK to connect.

    If this is your first time connecting to this instance, or if you have forgotten your password, see creating passwords for Windows instances.

Other

Windows supports other clients that also use the RDP protocol. Clients are made to support platforms such as Android, iOS, Mac, and Windows app among others.

For a list of officially supported clients, see Microsoft's Remote Desktop Clients article.

  1. Consult the documentation for the client you wish to use, and install it where needed.
  2. Identify the external IP of your Windows instance from the VM instances page, or the gcloud SDK command below:

    gcloud compute instances list
    
  3. Connect using external IP address of the client, and authenticate with username and password when prompted.

    If this is your first time connecting to this instance, or if you have forgotten your password, see creating passwords for Windows instances.

Should you have any difficulties with connecting, please see our troubleshooting guides.

Connect using the command line interface

If your use case or workflow allows you to connect without a graphical interface, connect using a command line connection method.

In most situations, you can use PowerShell PSSession, which is a connection to the instance through the instance's network address that offers the best feature set and ease of use.

To troubleshoot problems with your instances, you can connect to the serial console using either the console or the gcloud SDK.

PSSession

Enter-PSSession allows for native connection and commands using Windows PowerShell.

  1. Identify the external IP address of your Windows instance from the VM instances page or the gcloud instances list command:

    gcloud compute instances list
    
  2. Ensure you have a firewall rule that allows traffic on port 5986 to reach your instance. This can be done via the firewall rules page or by running the command below:

    gcloud compute firewall-rules list
    

    Should you need to add a new rule, please see our documentation for using firewalls.

  3. Open PowerShell on your local Windows machine and enter an interactive CMD session on your instance using the following command:

    Enter-PSSession -ComputerName [EXTERNAL_IP_ADDRESS] -UseSSL
    -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)
    -Credential $credentials
    
  4. Enter the username and password of the instance and press Enter to connect.

    Screenshot of the credential request generated by PowerShell

For more details about connecting to your instance using PowerShell, please see our advanced connection documentation.

Console

Connecting to the command line through the cloud web console allows for an easy web browser based connection.

  1. Open your Windows instance from the VM instances page in GCP Console.
  2. Set the instance metadata to allow for connecting to serial ports via the Edit button on the VM instance page.

    Screenshot of the edit instance details screen setting

    If you want the settings to apply to all instances in your project, set project-wide custom metadata instead.

  3. Click the dropdown arrow next to Connect to serial console, and select Serial port 2 to enter the interactive session.

  4. After you enter the Windows SAC, run the following commands to enter a CMD session:

    cmd
    ch -sn cmd0001
    Press any key to confirm connection to the channel.
    

    If CMD opens in another channel, enter the appropriate number instead of 0001.

  5. Enter the username, domain and password of the instance; and press Enter to connect. If the instance does not have a domain configured, leave this field blank.

gcloud SDK

Using gcloud to connect allows for compatibility between multiple operating systems and integrates with your native terminal application.

  1. Download and install the gcloud SDK if you have not done so already.
  2. Set the instance metadata to allow for connecting to serial ports via the Edit button on the VM instance page, or with the gcloud SDK command below:

    gcloud compute instances add-metadata [INSTANCE_NAME]
    --metadata=serial-port-enable=1
    

    If you want the settings to apply to all instances in your project, set project-wide custom metadata instead, or run the following gcloud SDK command:

    gcloud compute project-info add-metadata
    --metadata=serial-port-enable=1
    
  3. Open terminal on your local machine and run the below command to enter the interactive session:

    gcloud compute connect-to-serial-port [INSTANCE_NAME] --port=2
    

    Screenshot of the SAC interactive session

  4. After you enter the Windows SAC, run the following commands to enter a CMD session:

    cmd
    ch -sn cmd0001
    Press any key to confirm connection to the channel.
    

    If CMD opens in another channel, enter the appropriate number instead of 0001.

  5. Enter the username, domain, and password of the instance. Then press Enter to connect. If the instance does not have a domain configured, leave this field blank.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation