- NAME
- gcloud-compute-ssh - SSH into a virtual machine instance
- SYNOPSIS
-
gcloud compute ssh [USER@]INSTANCE [--command COMMAND] [--container CONTAINER] [--dry-run] [--format FORMAT] [--help] [--plain] [--project PROJECT] [--quiet, -q] [--ssh-flag SSH_FLAG] [--ssh-key-file SSH_KEY_FILE] [--zone ZONE] [-h]
- DESCRIPTION
-
gcloud compute ssh
is a thin wrapper around thessh(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
-
-
[USER@]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.
-
--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.
-
--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. -
--project
PROJECT
- Google Cloud Platform project to use for this invocation.
-
--quiet
- Disable all interactive prompts when running gcloud commands. If input is required, defaults will be used, or an error will be raised.
-
--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 my-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 “my-instance” is 162.222.181.197. -
--ssh-key-file
SSH_KEY_FILE
- The path to the SSH key file. By deault, 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”.
-
-h
- Print a summary help and exit.
-
- EXAMPLES
- To SSH into “my-instance” in zone “us-central2-a”, run:
-
$ gcloud compute ssh my-instance --zone us-central2-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 my-instance --zone us-central2-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 my-instance \ --zone us-central2-a \ --container my-container
gcloud compute ssh
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License , and code samples are licensed under the Apache 2.0 License . For details, see our Site Policies .
Last updated August 11, 2014.