Skip to content

ck gce

Commands for Compute Engine VMs in the active gcloud configuration. Log in first with ck gcloud login.

Command What it does
ls List VMs
ls-running List running VMs
ls-stopped List stopped VMs
start / stop / reset Change a VM’s power state
ssh SSH to a VM, run a command, or hold tunnels open
scp Copy files to or from a VM
port-forward Forward a port through IAP

All instance commands accept:

Option Meaning
--zone <zone> VM zone. When left out, it’s looked up from the VM name; if the name exists in more than one zone, you must pass it.
--project <project> Project to use instead of the configuration’s default

Flags can go anywhere on the line. Everything after a bare -- is passed through as-is.

ck gce ls [--filter <pattern>]

List VMs. --filter matches the name against a pattern.

Terminal window
ck gce ls
ck gce ls --filter web
ck gce ls-running

List VMs with status RUNNING.

ck gce ls-stopped

List VMs with status TERMINATED (stopped).

ck gce start <instance-name> [--zone <zone>] [--project <project>]
ck gce stop <instance-name> [--zone <zone>] [--project <project>]
ck gce reset <instance-name> [--zone <zone>] [--project <project>]

Start, stop, or hard-reset a VM.

Terminal window
ck gce start my-vm
ck gce stop my-vm --zone us-central1-a
ck gce ssh [instance-name] [--zone <zone>] [--project <project>]
[--tunnel-iap | --no-iap] [--forward <local:host:remote>]...
[--tunnel-only] [--] [command]

SSH to a VM. Leave out the name to pick from running VMs.

Option Meaning
--tunnel-iap Connect through IAP, so the VM needs no public IP. On by default when --forward is used.
--no-iap Never connect through IAP
--forward <local:host:remote> Forward a local port to host:remote as seen from the VM. Repeatable.
--tunnel-only With --forward: hold the tunnels open without a shell
command Run this command instead of opening a shell
Terminal window
ck gce ssh # pick a running VM
ck gce ssh my-vm --tunnel-iap
ck gce ssh my-vm "df -h" # run a remote command
# MySQL on the VM at localhost:3308, tunnel only (no shell)
ck gce ssh my-vm --forward 3308:127.0.0.1:3306 --tunnel-only
# two forwards at once
ck gce ssh my-vm --forward 3308:127.0.0.1:3306 --forward 6380:127.0.0.1:6379
ck gce scp <source>... <destination> [--zone <zone>] [--project <project>] [--tunnel-iap] [-r]

Copy files to or from a VM. Write remote paths as instance:path; the zone is looked up from the first remote path.

Option Meaning
--tunnel-iap Copy through IAP
-r, --recurse Copy directories
Terminal window
ck gce scp ./app.env my-vm:/tmp/
ck gce scp my-vm:/var/log/syslog ./syslog --zone us-central1-a
ck gce scp -r ./dist my-vm:/srv/app --tunnel-iap
ck gce port-forward <remote-port> <local-port> <instance-name> [host] [--zone <zone>] [--project <project>]

Forward a port to localhost through IAP. Arguments are in the same order as ck ec2 port-forward.

  • Without host: opens an IAP TCP tunnel to the VM’s own port.
  • With host: tunnels through the VM over SSH to a host it can reach, such as a Cloud SQL private IP.
Terminal window
ck gce port-forward 8080 8080 my-vm
ck gce port-forward 3306 3308 my-vm 10.20.0.5 # Cloud SQL private IP through the VM