NAME
gcloud compute ssh - SSH into a virtual machine instance
SYNOPSIS
gcloud compute ssh   INSTANCE   [--command   COMMAND]   [--container   CONTAINER]   [--dry-run]   [--format   FORMAT]   [--help]   [--plain]   [--project   PROJECT_ID]   [--quiet,   -q]   [--ssh-flag   SSH_FLAG]   [--ssh-key-file   SSH_KEY_FILE]   [--zone   ZONE]   [-h]
DESCRIPTION
gcloud compute ssh is a thin wrapper around the ssh(1) command that takes care of authentication and the translation of the instance name into an IP address.
This command ensures that the user’s public SSH key is present in the project’s metadata. If the user does not have a public SSH key, one is generated using ssh-keygen(1).
POSITIONAL ARGUMENTS
INSTANCE
Specifies the instance to SSH into.
USER specifies the username with which to SSH. If omitted, $USER from the environment is selected.
FLAGS
--command COMMAND
A command to run on the virtual machine.
--container CONTAINER
The name of a container inside of the virtual machine instance to connect to. This only applies to virtual machines that are using a Google container virtual machine image. For more information, see https://developers.google.com/compute/docs/containers.
--dry-run
If provided, prints the command that would be run to standard out instead of executing it.
--plain
Suppresses the automatic addition of ssh(1)/scp(1) flags. This flag is useful if you want to take care of authentication yourself or re-enable strict host checking.
--ssh-flag SSH_FLAG
Additional flags to be passed to ssh(1). It is recommended that flags be passed using an assignment operator and quotes. This flag will replace occurences of %USER% and %INSTANCE% with their dereferenced values. Example:
$ gcloud compute ssh example-instance --zone us-central1-a \
    --ssh-flag="-vvv" --ssh-flag="-L 80:%INSTANCE%:80"
is equivalent to passing the flags --vvv and _-L 80:162.222.181.197:80_ to ssh(1) if the external IP address of example-instance is 162.222.181.197.
--ssh-key-file SSH_KEY_FILE
The path to the SSH key file. By default, this is ~/.ssh/google_compute_engine.
--zone ZONE
The zone of the instance to connect to. If not specified, you will be prompted to select a zone.
To avoid prompting when this flag is omitted, you can set the compute/zone property:
$ gcloud config set compute/zone ZONE
A list of zones can fetched by running:
$ gcloud compute zones list
To unset the property, run:
$ gcloud config unset compute/zone
Alternatively, the zone can be stored in the environment variable CLOUDSDK_COMPUTE_ZONE.
GLOBAL FLAGS
--format FORMAT
Specify a format for printed output. By default, a command-specific human-friendly output format is used. Setting this flag to one of the available options will serialize the result of the command in the chosen format and print it to stdout. Supported formats are: json, text, yaml.
--help
Display detailed help.
--project PROJECT_ID
The Google Cloud Platform project name to use for this invocation. If omitted then the current project is assumed.
--quiet, -q
Disable all interactive prompts when running gcloud commands. If input is required, defaults will be used, or an error will be raised.
-h
Print a summary help and exit.
EXAMPLES
To SSH into example-instance in zone us-central1-a, run:
$ gcloud compute ssh example-instance --zone us-central1-a
You can also run a command on the virtual machine. For example, to get a snapshot of the guest’s process tree, run:
$ gcloud compute ssh example-instance --zone us-central1-a \
    --command "ps -ejH"
If you are using the Google container virtual machine image, you can SSH into one of your containers with:
$ gcloud compute ssh example-instance --zone us-central1-a \
    --container CONTAINER
NOTES
This command is in the Google Cloud SDK compute component. See installing components if it is not installed.