gcloud compute connect-to-serial-port Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud compute connect-to-serial-port - connect to the serial port of an instance
- SYNOPSIS
gcloud compute connect-to-serial-port[USER@]INSTANCE[--dry-run][--extra-args=KEY=VALUE,[KEY=VALUE,…]][--force-key-file-overwrite][--location=LOCATION][--port=PORT; default=1][--ssh-key-file=SSH_KEY_FILE][--zone=ZONE][--ssh-key-expiration=SSH_KEY_EXPIRATION|--ssh-key-expire-after=SSH_KEY_EXPIRE_AFTER][GCLOUD_WIDE_FLAG …]
- DESCRIPTION
gcloud compute connect-to-serial-portallows users to connect to,and interact with, a VM's virtual serial port using ssh as the secure,authenticated transport protocol.The user must first enable serial port access to a given VM by setting the'serial-port-enable=true' metadata key-value pair. Setting 'serial-port-enable'on the project-level metadata enables serial port access to all VMs in theproject.
This command uses the same SSH key pair as the
gcloud compute sshcommandand also ensures that the user's public SSH key is present in the project'smetadata. If the user does not have a public SSH key, one is generated usingssh-keygen.- EXAMPLES
- To connect to the serial port of the instance 'my-instance' in zone'us-central1-f', run:
gcloudcomputeconnect-to-serial-portmy-instance--zone=us-central1-f - POSITIONAL ARGUMENTS
- [
USER@]INSTANCE - Specifies the user/instance for the serial port connection.
specifies the username to authenticateas. If omitted, the current OS user is selected.USER
- [
- FLAGS
--dry-run- If provided, the ssh command is printed to standard out rather than beingexecuted.
--extra-args=KEY=VALUE,[KEY=VALUE,…]- Optional arguments can be passed to the serial port connection by passingkey-value pairs to this flag, such as max-connections=N or replay-lines=N. Seehttps://cloud.google.com/compute/docs/instances/interacting-with-serial-consolefor additional options.
--force-key-file-overwrite- If enabled, the gcloud command-line tool will regenerate and overwrite the filesassociated with a broken SSH key without asking for confirmation in bothinteractive and non-interactive environments.
If disabled, the files associated with a broken SSH key will not be regeneratedand will fail in both interactive and non-interactive environments.
--location=LOCATION- If provided, the region in which the serial console connection will occur. Mustbe the region of the VM to connect to.
--port=PORT; default=1- The number of the requested serial port. Can be 1-4, default is 1.
Instances can support up to four serial ports. By default, this command willconnect to the first serial port. Setting this flag will connect to therequested serial port.
--ssh-key-file=SSH_KEY_FILE- The path to the SSH key file. By default, this is
.~/.ssh/google_compute_engine --zone=ZONE- Zone of the instance to connect to. If not specified and the
property isn't set, you mightbe prompted to select a zone (interactive mode only).compute/zoneTo avoid prompting when this flag is omitted, you can set the
property:compute/zonegcloudconfigsetcompute/zoneZONEA list of zones can be fetched by running:
gcloudcomputezoneslistTo unset the property, run:
gcloudconfigunsetcompute/zoneAlternatively, the zone can be stored in the environment variable
.CLOUDSDK_COMPUTE_ZONE - At most one of these can be specified:
--ssh-key-expiration=SSH_KEY_EXPIRATION- The time when the ssh key will be valid until, such as"2017-08-29T18:52:51.142Z." This is only valid if the instance is not using OSLogin. See $gcloud topicdatetimes for information on time formats.
--ssh-key-expire-after=SSH_KEY_EXPIRE_AFTER- The maximum length of time an SSH key is valid for once created and installed,e.g. 2m for 2 minutes. See $gcloud topic datetimes forinformation on duration formats.
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- These variants are also available:
gcloudalphacomputeconnect-to-serial-portgcloudbetacomputeconnect-to-serial-port
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-07 UTC.