GCLOUD_COMPUTE_SSH(1)

NAME

gcloud compute ssh - SSH into a virtual machine instance

SYNOPSIS

gcloud compute ssh [USER@]INSTANCE [--command COMMAND] [--container CONTAINER] [--dry-run] [--plain] [--ssh-flag SSH_FLAG] [--ssh-key-file SSH_KEY_FILE] [--strict-host-key-checking STRICT_HOST_KEY_CHECKING] [--zone ZONE] [GLOBAL-FLAG ...] [-- IMPLEMENTATION-ARGS ...]

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) (if the --quiet flag is given, the generated key will have an empty passphrase).

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.
[-- IMPLEMENTATION-ARGS ...]
    Flags and positionals passed to the underlying ssh implementation. The '--' argument must be specified between gcloud specific args on the left and IMPLEMENTATION-ARGS on the right. Example:
        $ gcloud compute ssh example-instance --zone us-central1-a -- -vvv \
            -L 80:%INSTANCE%:80

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://cloud.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 use specific ssh/scp features.
--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.
--strict-host-key-checking STRICT_HOST_KEY_CHECKING
    Override the default behavior of StrictHostKeyChecking. By default, StrictHostKeyChecking is set to 'no' the first time you connect to an instance and will be set to 'yes' for all subsequent connections. Use this flag to specify a value for the connection.
--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 be 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
Run $ gcloud help for a description of flags available to all commands.

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