gcloud compute ssh web-server --zone us-central1-a --command 'uptime'

Category: Google Cloud & Workspace

gcloud compute ssh web-server --zone us-central1-a --command 'uptime'

Run one command on a VM over SSH

Executes the quoted command on the instance and prints the output, then closes the connection, which makes it perfect for scripts and one-off checks. Chain several steps with && inside the quotes. Interactive sessions without --command are covered by plain gcloud compute ssh.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.