Google Cloud CLI (gcloud) cheatsheet

Google Cloud CLI (gcloud): Compute Engine

7 common Google Cloud CLI (gcloud) tasks.

List VM instances

Show the VMs in the project.

gcloud compute instances list

Create a VM

Create a small Debian VM in a zone.

gcloud compute instances create my-vm --zone us-central1-a --machine-type e2-small --image-family debian-12 --image-project debian-cloud

Connect to a VM with SSH

SSH into an instance. gcloud manages the keys.

gcloud compute ssh my-vm --zone us-central1-a

Stop a VM

Stop an instance. You stop paying for compute but not for its disks.

gcloud compute instances stop my-vm --zone us-central1-a

Delete a VM

Delete a VM instance permanently.

gcloud compute instances delete my-vm --zone us-central1-a

Caution: Deleting is permanent, and boot disks are deleted by default.

Copy a file to a VM

Copy a local file to an instance.

gcloud compute scp ./file.txt my-vm:~/ --zone us-central1-a

Allow traffic to a port

Create a firewall rule that allows HTTPS from anywhere.

gcloud compute firewall-rules create allow-https --allow tcp:443

Was this page helpful?