Common gcloud compute commands Stay organized with collections Save and categorize content based on your preferences.
This document lists some of the most commonly usedgcloud compute commands.
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:
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.
Describing projects
Run the following command to query information about your Compute Engineproject, such as project metadata, ssh keys, and quota metrics:
gcloud compute project-info describe
For more information about describing your project, see thegcloud compute project-info describereference documentation.
Working with VMs
The following examples show common tasks when working with virtual machine (VM)instances. For more information about virtual machine (VM) instances, seeVirtual machine instances.
Creating VMs
Run the following command to create a VM:
gcloud compute instances createVM_NAME \ [--imageIMAGE | --image-familyIMAGE_FAMILY] \ --image-projectIMAGE_PROJECT
Replace the following:
VM_NAME: thename of the new VM.IMAGEorIMAGE_FAMILY: Specify one of the following:IMAGE: required version of a public image. Forexample,--image debian-10-buster-v20200309.IMAGE_FAMILY: animage family. Thiscreates the VM from the most recent, non-deprecated OS image. For example,if you specify--image-family debian-10, Compute Engine creates a VMfrom the latest version of the OS image in the Debian 10 image family.
IMAGE_PROJECT: theproject containing the image.
For more information about creating VMs, seeCreating and starting a VM instanceand thegcloud compute instances createreference documentation.
Listing VMs
Run the following command to display all VMs in a project:
gcloud compute instances list
For more information about listing VMs, see thegcloud compute instances listreference documentation.
Listing VMs with GPUs
Run the following command to display all the VMs with GPUs in a project:
gcloud compute instances list --filter="guestAccelerators.acceleratorCount>0" --format="table(name,zone,guestAccelerators.acceleratorType,guestAccelerators.acceleratorCount,disks.type)"
Listing VMs with local SSDs
Run the following command to display all the VMs with local SSDs in a project:
gcloud compute instances list --filter="disks.type='SCRATCH'" --format="table(name,zone,guestAccelerators.acceleratorType,guestAccelerators.acceleratorCount,disks.type)"
Describing VMs
Run the following command to display all data associated with a VM:
gcloud compute instances describeVM_NAME
ReplaceVM_NAME with the name of the VM.
For more information about describing VMs, see thegcloud compute instances describereference documentation.
Starting VMs
Run the following command to start a stopped VM:
gcloud compute instances startVM_NAME
ReplaceVM_NAME with the name of the VM.
For more information about starting VMs, seeStarting and stopping an instanceand thegcloud compute instances startreference documentation.
Stopping VMs
Run the following command to stop a VM:
gcloud compute instances stopVM_NAME
ReplaceVM_NAME with the name of the VM.
For more information about stopping VMs, seeStarting and stopping an instanceand thegcloud compute instances stopreference documentation.
Adding labels to VMs
Run the following command to add labels to VMs:
gcloud compute instances add-labelsVM_NAME \ --labels=KEY=VALUE
Replace the following:
VM_NAME: the name of the VM.KEY=VALUE: the key-value pair of the label.
For more information about labeling VMs, seeLabeling resourcesand thegcloud compute instances add-labelsreference documentation.
Connecting to VMs
Using SSH to connect to instances
Run the following command to connect to a VM using SSH:
gcloud compute sshVM_NAME
ReplaceVM_NAME with the name of the VM.
For more information about connecting to VMs using SSH, seeConnecting to Linux VMsand thegcloud compute sshreference documentation.
Using SCP to transfer files to instances
Run the following command to copy files to a VM:
gcloud compute scpLOCAL_FILE_PATHVM_NAME:REMOTE_DIRECTORY
Run the following command to copy files from a VM:
gcloud compute scpVM_NAME:REMOTE_DIRECTORYLOCAL_FILE_PATH
Replace the following:
LOCAL_FILE_PATH: The path to the file on your workstation.VM_NAME: The name of your VM.REMOTE_DIRECTORY: The path to the directory on your VM.
For more information about transferring files to and from VMs using SCP, seeTransferring files using the Google Cloud CLIand thegcloud compute scpreference documentation.
Working with disks
The following example shows a common task when working with disks. For moreinformation about disks, seeStorage options.
Listing disks
Run the following command to display all disks in a project:
gcloud compute disks list
For more information about listing disks, see thegcloud compute disks listreference documentation.
Working with snapshots
The following examples show common tasks when working with snapshots. For moreinformation about snapshots, seePersistent disk snapshots.
Listing snapshots
Run the following command to display all snapshots in a project:
gcloud compute snapshots list
For more information about describing snapshots, see thegcloud compute snapshots listreference documentation.
Describing snapshots
Run the following command to display all data associated with a snapshot:
gcloud compute snapshots describeSNAPSHOT_NAME
ReplaceSNAPSHOT_NAME with the name of the snapshot.
For more information about describing snapshots, see thegcloud compute snapshots describereference documentation.
Deleting snapshots
Run the following command to delete a snapshot:
gcloud compute snapshots deleteSNAPSHOT_NAME
ReplaceSNAPSHOT_NAME with the name of the snapshot.
For more information about deleting snapshots, seeDeleting a snapshotand thegcloud compute snapshots deletereference documentation.
Working with firewall rules
The following examples show common tasks when working with firewall rules. Formore information about firewall rules, seeVPC firewall rules overview.
Describing firewall rules
Run the following command to display all data associated with a firewall rule:
gcloud compute firewall-rules describeFIREWALL_RULE_NAME
ReplaceFIREWALL_RULE_NAME with the name of the firewallrule.
For more information about describing firewall rules, see thegcloud compute firewall-rules describereference documentation.
Creating firewall rules
Run the following command to create a firewall rule:
gcloud compute firewall-rules createFIREWALL_RULE_NAME \ [--allow=PROTOCOL:PORT | --action=ACTION --rules=PROTOCOL:PORT]
Specify either--allow or--action and--rules, and replace the following:
FIREWALL_RULE_NAME: the name of the firewall rule.ACTION: the action on match. Eitherallowordeny.PROTOCOL:PORT: the protocol and port whosetraffic will be affected by the firewall rule.
For more information about creating firewall rules, seeCreating firewall rulesand thegcloud compute firewall-rules createreference documentation.
Working with managed instances groups (MIGs)
The following examples show common tasks when working with MIGs. Formore information about MIGs, seeManaged instance groups (MIGs).
Creating managed instance groups
Run the following command to create a MIG:
gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \ --size=SIZE \ --template=INSTANCE_TEMPLATE_URL
Replace the following:
INSTANCE_GROUP_NAME: the name for this instance groupSIZE: the size of the instance groupINSTANCE_TEMPLATE_URL: the URL of the instance template that you want touse to create VMs in the MIG. The URL can contain either theIDor name of the instance template. Specify one of the following values:- For a regional instance template:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID - For a global instance template:
INSTANCE_TEMPLATE_ID
- For a regional instance template:
For more information about creating MIGs, seeBasic scenarios for creating a MIGand thegcloud compute instance-groups managed createreference documentation.
Setting autoscaling
Run the following command to set autoscaling on a MIG, based on CPU utilization:
gcloud compute instance-groups managed set-autoscalingINSTANCE_GROUP_NAME \ --max-num-replicas=MAX_NUM_REPLICAS \ --target-cpu-utilization=TARGET_CPU_UTILIZATION
Replace the following:
INSTANCE_GROUP_NAME: the name of a MIGMAX_NUM_REPLICAS: the maximum number of replicas theautoscaler can createTARGET_CPU_UTILIZATION: the CPU level the autoscalershould maintain, between0.0and1.0
For more information about setting autoscaling, seeAutoscaling groups of instancesand thegcloud compute instance-groups managed set-autoscalingreference documentation.
Working with metadata
The following example shows a common task when working with metadata. For moreinformation about metadata, seeStoring and retrieving metadata.
Adding project-level metadata
Run the following command to add metadata to your project:
gcloud compute project-info add-metadataVM_NAME \ --metadata=KEY=VALUE,[KEY=VALUE]
Replace the following:
VM_NAME: the name of the VMKEY=VALUE: the metadata key-value pair
For more information about adding metadata to VMs, seeSetting project-wide custom metadataand thegcloud compute project-info add-metadatareference documentation.
Adding instance-level metadata
Run the following command to add metadata to a VM:
gcloud compute instances add-metadataVM_NAME \ --metadata=KEY=VALUE,[KEY=VALUE]
Replace the following:
VM_NAME: the name of the VMKEY=VALUE: the metadata key-value pair
For more information about adding metadata to VMs, seeSetting instance metadataand thegcloud compute instances add-metadatareference documentation.
Getting help pages
The following commands show how to access different types of help, fromgeneral help about thegcloud computecommand, to specific help about aresource group (instances) or a command (create). Comprehensive help for allresources and commands follows this pattern:
gcloud compute --help
gcloud compute instances --help
gcloud compute instances create --help
Quick help can be obtained by using the-h flag instead of the--help flag.You can also review all of the comprehensive help atGoogle Cloud CLI Reference.
For comprehensive help with commands specifically for configuring thegcloud CLI, run:
gcloud topicTOPIC
ReplaceTOPIC with the topic you want help with. Fora list of topics you can get help for, see thegcloud topic reference documentation.
What's next?
- ViewThe Google Cloud CLI cheat sheet forinformation about go-to commands for several Google Cloud products.
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 2026-02-19 UTC.