Connect to Windows VMs using SSH Stay organized with collections Save and categorize content based on your preferences.
Preview
This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.
This document describes how to connect to Windows virtual machine (VM)instances using SSH. For other ways to connect to Windows VMs, seeConnect to Windows VMs using RDPandConnect to Windows VMs using PowerShell.To learn about how SSH works in Compute Engine, seeAbout SSH connections.
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 images
SSH for Windows is supported onWindows Server images runningthe guest agent (GCEGuestAgent) version20220527.00 or later and OpenSSHversion8.6 or later.
Enable SSH for Windows VMs
To enable SSH connections to Windows VMs, install thegoogle-compute-engine-ssh package and set theenable-windows-ssh key toTRUE in project or instance metadata. Enabling SSH for Windows in projectmetadata enables SSH for all Windows VMs in your project. Enabling SSH forWindows in instance metadata enables SSH for a single VM and overrides the valueset in project metadata.
Enable SSH for Windows while creating a VM
Enable SSH for Windows while creating a VM using the Google Cloud console or theGoogle Cloud CLI.
Console
Create a VM from a public imagethat installs thegoogle-compute-engine-ssh package and enables SSH onstartup:
Specify the followingBoot disk properties:
- Operating system: Windows Server
- Version: Any version
In theAdvanced options section, expand theManagement section.
In theMetadata section, clickAdd item. Add a startup scriptthat installs the
google-compute-engine-sshpackage by entering thefollowing metadata key-value pair:- Key:
sysprep-specialize-script-cmd - Value:
googet -noconfirm=true install google-compute-engine-ssh
- Key:
In theMetadata section, clickAdd item. Set
enable-windows-sshtoTRUEby entering the following metadata key-value pair:- Key:
enable-windows-ssh - Value:
TRUE
- Key:
ClickCreate to create and start the VM.
gcloud
Run the followinggcloud compute instances create commandto create a Windows Server VM that installs thegoogle-compute-engine-sshpackage and enables SSH on startup:
gcloud compute instances createVM_NAME \ --image-family=IMAGE_FAMILY \ --image-project=windows-cloud \ --metadata sysprep-specialize-script-cmd="googet -noconfirm=true install google-compute-engine-ssh",enable-windows-ssh=TRUE
Replace the following:
VM_NAME: the name of the new VM.IMAGE_FAMILY: aWindows Server image family.This creates the VM from the most recent non-deprecated Windows Serverimage.
Enable SSH for Windows on a running VM
To enable SSH on a running Windows VM, do one of the following, depending onwhether you can use RDP to access your VM or if your workload can tolerate areboot:
- RDP access required: Connect to the VM using RDP and install the SSHpackage
Reboot required: Use a startup script to install the SSH package
RDP
If you can access your VM using RDP, enable SSH by doing the following:
Open an administrator Command Prompt session by doing the following:
Open theStart menu.
Navigate toCommand Prompt.
Right-clickCommand Prompt and selectRun as administrator.
If you are prompted to allow Command Prompt to make changes to your device,selectYes.
Download and install the
google-compute-engine-sshpackage by running thefollowing command:googet -noconfirm=true install google-compute-engine-windows && googet -noconfirm=true install google-compute-engine-ssh
Close the RDP session.
Enable Windows SSH in metadata by setting the
enable-windows-sshkey toTRUE. For more information about setting metadata, seeSet custom metadata.
Startup script
If you can't access your VM using RDP, enable SSH by doing the following:
Set the following metadata key-value pairs on the VM to enable SSH. Formore information about setting metadata, seeSet custom metadata.
SSH package installation metadata:
- Key:
windows-startup-script-cmd - Value:
googet -noconfirm=true update && googet -noconfirm=true install google-compute-engine-ssh
- Key:
SSH enablement metadata:
- Key:
enable-windows-ssh - Value:
TRUE
- Key:
Start the VM.The VM might take a few minutes to reboot.
Connect to VMs using SSH
Connect to VMs using thegcloud compute ssh command:
gcloud compute sshVM_NAME
ReplaceVM_NAME with the name of the Windows VM thatyou want to connect to.
Connect to VMs that use AD
If the VM you're connecting to uses Active Directory (AD), connect using thefollowing command:
gcloud compute sshDOMAIN\USERNAME@VM_NAME
Replace the following:
DOMAIN: your AD domain. For example the domain of thead.example.comAD, isexample.USERNAME: your AD username. For example,cloudysanfrancisco.VM_NAME: the name of the Windows VM that you want toconnect to.
What's next?
- Learn how totroubleshoot SSH connections.
- Learn how toAdd SSH keys to VMs
- Learn how toRestrict SSH keys from VMs.
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.