Troubleshooting using the serial console

Linux Windows

This page describes how to enable interactive access to an instance'sserial console to debug boot and networking issues, troubleshoot malfunctioninginstances, interact with the GRand Unified Bootloader (GRUB), and perform othertroubleshooting tasks.

Note: You can't enable interactive access to the serial console for bare metalinstances; the serial console is read-only for bare metal instances. To executecommands interactively, you can connect to the instance using SSH after theinstance starts.

A virtual machine (VM) instance has four virtual serial ports. Interactingwith a serial port is similar to using a terminal window, in that input andoutput is entirely in text mode and there is no graphical interface or mousesupport. The instance's operating system, BIOS, and other system-levelentities often write output to the serial ports, and can accept input suchas commands or answers to prompts. Typically, these system-level entities usethe first serial port (port 1) and serial port 1 is often referred to as theserial console.

If you only need to view serial port output without issuing any commands tothe serial console, you can call thegetSerialPortOutputmethod or use Cloud Logging to read information that your instance haswritten toits serial port; seeViewing serial port logs.However, if you run into problems accessing your instance through SSH or need totroubleshoot an instance that is not fully booted, you can enable interactiveaccess to the serial console, which lets you connect to and interact with any ofyour instance's serial ports. For example, you can directly run commandsand respond to prompts in the serial port.

When you enable or disable the serial port, you can use any Boolean value thatis accepted by the metadata server. For more information, seeBoolean values.

Before you begin

Permissions required for this task

To perform this task, you must have the followingpermissions:

  • compute.instances.setMetadata on the VM if enabling interactive access on a specific VM
  • compute.projects.setCommonInstanceMetadata on the project, if enabling interactive access for all VMs in the project
  • iam.serviceAccountUser role on the instance's service account

Enabling interactive access on the serial console

Enable interactive serial console access for individual VM instances or foran entire project.

Caution: The interactive serial console does not support IP-based accessrestrictions such as IP allowlists, unless you useVPC Service Controls.If you enable the interactive serial console on an instance, clients can attemptto connect to that instance from any IP address. Anybody can connect to thatinstance if they know the correct SSH key, username, project ID, zone, andinstance name.

Enabling access for a project

Enabling interactive serial console access on a project enables access for allVM instances that are part of that project.

By default, interactive serial port access is disabled. You can also explicitlydisable it by setting theserial-port-enable key toFALSE. Ineither case, any per-instance setting overrides the project-level setting orthe default setting.

Console

  1. In the Google Cloud console, go to theMetadata page.

    Go to Metadata

  2. ClickEdit to edit metadata entries.
  3. Add a new entry that uses the keyserial-port-enable and valueTRUE.
  4. Save your changes.

gcloud

Using the Google Cloud CLI, enter theproject-info add-metadatacommand as follows:

gcloud compute project-info add-metadata \    --metadata serial-port-enable=TRUE

REST

In the API, make a request to theprojects().setCommonInstanceMetadatamethod, providing theserial-port-enable key with a value ofTRUE:

{ "fingerprint": "FikclA7UBC0=", "items": [  {   "key": "serial-port-enable",   "value": "TRUE"  } ]}

Enabling access for a VM instance

Enable interactive serial console access for a specific instance. A per-instancesetting, if it exists, overrides any project-level setting. You can alsodisable access for a specific instance, even if access is enabled on the projectlevel, by settingserial-port-enable toFALSE, instead ofTRUE. Similarly,you can enable access for one or more instances even if it is disabled for theproject, explicitly or by default.

Console

  1. In the Google Cloud console, go to theVM instances page.

    Go to the VM instances page

  2. Click the instance you want to enable access for.
  3. ClickEdit.
  4. Under theRemote access section, toggle theEnable connecting toserial ports checkbox.
  5. Save your changes.

gcloud

Using the Google Cloud CLI, enter theinstances add-metadatacommand, replacinginstance-name with the name ofyour instance.

gcloud compute instances add-metadatainstance-name \    --metadata serial-port-enable=TRUE

REST

In the API, make a request to theinstances().setMetadatamethod with theserial-port-enable key and a value ofTRUE:

POST https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-instance/setMetadata{ "fingerprint": "zhma6O1w2l8=", "items": [  {   "key": "serial-port-enable",   "value": "TRUE"  } ]}

Configure serial console for a bare metal instance

For bare metal instances, increase the bit rate, also known as baud rate, forthe serial console to 115,200 bps (~11.5kB/sec). Using a slower speed resultsin garbled or missing console output.

Bootloader configuration varies between operating systems and OS versions. Referto the OS distributor's documentation for instructions.

If modifying the bit rate on the command line for the current session, use acommand similar to the following:

console=ttyS0,115200

If modifying the GRUB configuration, use a command similar to the following:

serial --speed=115200

Make sure that you update the actual bootloader configuration. This can be donewithupdate-grub,grub2-mkconfig, or a similar command.

Connecting to a serial console

Compute Engine offers regional serial console gateways for each Google Cloudregion. After enabling interactive access for a VM's serial console, youcan connect to a regional serial console.

The serial console authenticates users withSSH keys. Specifically, you must add yourpublic SSH key to the project or instance metadata and store your private keyon the local machine from which you want to connect. The gcloud CLIand the Google Cloud console automatically add SSH keys to the project for you.If you are using a third-party client, you might need to add SSH keys manually.

If you are using a third-party client, you can additionallyvalidate the connection using the serial console's host keys.When you use the Google Cloud CLI to connect, host key authentication is doneautomatically on your behalf.

Caution: Directly connecting to the serial console using its IP address ratherthan its hostname is not recommended. Serial console IP addresses can changewithout notice.

Console

To connect to a VM's regional serial console, do the following:

  1. In the Google Cloud console, go to theVM instances page.

    Go to the VM instances page

  2. Click the instance you want to connect to.
  3. UnderDetails, clickConnect to serial console toconnect on the default port (port 1).
  4. If you want to connect to another serial port, click the down arrow nextto theConnect to serial console button and change the port numberaccordingly.
  5. For Windows instances, open the drop-down menu next tothe button and connect toPort 2 to access the serial console.

gcloud

Caution: As of March 31, 2025, the serial console SSH host key endpointwas deprecated and a new endpoint was introduced. We recommend that youupdate gcloud CLI toversion 515.0.0 or later to enable you to use the new endpoint. For moreinformation, seeSerial console SSH key endpoint deprecation.

To connect to a VM's regional serial console, use thegcloud compute connect-to-serial-port command:

gcloud compute connect-to-serial-portVM_NAME \    --port=PORT_NUMBER

Replace the following:

Other SSH clients

Note: You must have added your public key to the project or instancemetadatabefore you can use a third-party SSH client. If you have used thegcloud CLI in the past to connect to other instances in thesame project, yourPUBLIC_KEY_FILE is likely locatedat$HOME/.ssh/google_compute_engine.pub. If you have never connected toan instance in this project before (so have never added public keys), youneed to add your SSH keys to the project or instance metadata beforeyou can connect using a third-party SSH client. SeeManaging SSH keys in metadatafor more information.

You can connect to an instance's serial console using other third-party SSHclients, as long as the client lets you connect to TCP port 9600. Beforeyou connect, you can optionallyvalidate the connection using the serial console's host keys.

Caution: As of March 31, 2025, the serial console SSH host key endpointwas deprecated and a new endpoint was introduced. If you previouslyset up your SSH client to validate the serial console's SSH host key,we recommend that you repeat this process using the new endpoint. For moreinformation, seeSerial console SSH host key endpoint deprecation.

To connect to a VM's regional serial console, run one of the followingcommands, depending on your VM's OS:

  • To connect to a Linux VM:

    ssh -iPRIVATE_SSH_KEY_FILE -p 9600PROJECT_ID.ZONE.VM_NAME.USERNAME.OPTIONS@REGION-ssh-serialport.googleapis.com
  • To connect to a Windows VM:

    ssh -iPRIVATE_SSH_KEY_FILE -p 9600PROJECT_ID.ZONE.VM_NAME.USERNAME.OPTIONS.port=2@REGION-ssh-serialport.googleapis.com

Replace the following:

  • PRIVATE_SSH_KEY_FILE: The private SSH key for theinstance.
  • PROJECT_ID: The project ID for this VM instance.
  • ZONE: The zone of the VM instance.
  • REGION: The region of the VM instance.
  • VM_NAME: The name of the VM instance.
  • USERNAME: The username you are using to connectto your instance. Typically, this is the username on your local machine.
  • OPTIONS: Additional options you can specify forthis connection. For example, you can specify a certain serial port andspecify anyadvanced option. The port number can be1 through 4, inclusively. To learn more about port numbers, seeunderstanding serial port numbering.If omitted, you will connect to serial port 1.
Caution: The global serial console gateway wasdeprecated on April 30, 2024 and is no longer available for use in newprojects or projects where it hasn't previously been used. If youuse the global serial console gateway, transition to using regional gatewaysinstead. For more information, seeGlobal serial console gateway deprecation.

To connect to the global serial console gateway, replaceREGION-ssh-serialport.googleapis.com withssh-serialport.googleapis.com as the hostname.

If you are having trouble connecting using a third-party SSH client, you canrun thegcloud compute connect-to-serial-port command with the--dry-runcommand-line option to see the SSH command that it would have run on yourbehalf. Then you can compare the options with the command you are using.

Validate third-party SSH client connections

When you use a third-party SSH client that isn't the Google Cloud CLI, werecommend that you verify that you're protected against impersonation orman-in-the-middle attacks by checking Google's Serial Port SSH host key. To setup your system to check the SSH host key, complete the following steps:

  1. Download the SSH host key for the serial console you will be using:

  2. Open your known hosts file, generally located at~/.ssh/known_hosts.

  3. Add the contents of the SSH host key, with the server's hostnameprepended to the key. For example, if the us-central1 server key contains the linessh-rsa AAAAB3NzaC1yc..., then~/.ssh/known_hosts should have a linelike this:

    [us-central1-ssh-serialport.googleapis.com]:9600 ssh-rsa AAAAB3NzaC1yc...

For security reasons, Google might occasionally change the Google Serial PortSSH host key. If your client fails to authenticate the server key, immediatelyend the connection attempt and complete the earlier steps to download a newGoogle Serial Port SSH host key.

If, after updating the host key, you continue to receive a host authenticationerror from your client, stop attempts to connect to the serial port and contactGoogle support. Don't provide any credentials over a connection wherehost authenticationhas failed.

Disconnecting from the serial console

To disconnect from the serial console, follow the instructions for the methodyou used to connect.

Console

In the Google Cloud console, disconnect from the serial console by doing thefollowing:

  1. Close the browser window or tab that contains the serial consoleconnection.

gcloud

In the Google Cloud CLI, disconnect from the serial console by doing thefollowing:

  1. Press theENTER key.
  2. Type~. (tilde, followed by a period).

Other SSH clients

In other SSH clients, disconnect from the serial console by doing thefollowing:

  1. Press theENTER key.
  2. Type~. (tilde, followed by a period).

In the Google Cloud CLI, or using SSH, you can discover other commands bytyping~?. You can also examine the man page for SSH with the followingcommand:

man ssh

Don't try to disconnect using any of the following methods:

  • TheCTRL+ALT+DELETE key combination or other similar combinations. Thisdoesn't work because the serial console does not recognize PC keyboardcombinations.

  • Theexit orlogout command doesn't work because the guest is not awareof any network or modem connections. Using this command causes the consoleto close and then reopen again, and you remain connected to the session. Ifyou would like to enableexit andlogout commands for your session,you can enable it by setting theon-dtr-low option.

Connecting to a serial console with a login prompt

If you are trying to troubleshoot an issue with a VM that has bootedcompletely or trying to troubleshoot an issue that occurs after VMhas booted past single user mode, you might be prompted for login informationwhen trying to access the serial console.

By default, Google-supplied Linux system images are not configured to allowpassword-based logins for local users. However, Google-supplied Windows imagesare configured to allow password-based logins for local users.

If your VM is running an image that is preconfigured with serial port logins,you need to set up a local password on the VM so that you can sign in to theserial console, if prompted. You can set up a local password after connecting tothe VM or by using a start-up script.

Note: This step is not required if you are interacting with the system duringor prior to boot or with some serial-port-based service that does not require apassword. This step is also not required if you have configuredgetty to signin automatically without a password using the "-a root" flag.

Setting up a local password using a startup script

You can use a startup script to set up a local password that lets youconnect to the serial console during or after VM creation.

To set up a local password in an existing VM, select one of the followingoptions:

Linux

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. In theName column, click the name of the VM for which you want toadd a local password.

    The details page of the VM opens.

  3. ClickEdit.

    The page to edit the details of the VM opens.

  4. In theMetadata>Automationsection, do the following:

    1. If the VM has an existing startup script, then remove it and storethe script somewhere safe.

    2. Add the following startup script:

      #!/bin/bashuseraddUSERNAMEecho 'USERNAME:PASSWORD' | chpasswdusermod -aG google-sudoersUSERNAME

      Replace the following:

      • USERNAME: the username that you want to add.

      • PASSWORD: the password for the username. Assome operating systems require minimal password length andcomplexity, specify a password as follows:

        • Use at least 12 characters.

        • Use a mix of upper and lower case letters, numbers, andsymbols.

  5. ClickSave.

    The details page of the VM opens.

  6. ClickReset.

  7. Connect to the serial console.

  8. When prompted, enter your login information.

Windows

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. In theName column, click the name of the VM for which you want toadd a local password.

    The details page of the VM opens.

  3. ClickEdit.

    The page to edit the details of the VM opens.

  4. In theMetadata section, do the following:

    1. If the VM has an existing startup script, then store the scriptsomewhere safe, and then, to delete the script, clickDelete item.

    2. ClickAdd item.

    3. In theKey field, enterwindows-startup-script-cmd.

    4. In theValue field, enter the following script:

      net userUSERNAMEPASSWORD /ADD /Ynet localgroup administratorsUSERNAME /ADD

      Replace the following:

      • USERNAME: the username that you want to add.

      • PASSWORD: the password for the username. Assome operating systems require minimal password length andcomplexity, specify a password as follows:

        • Use at least 12 characters.

        • Use a mix of upper and lower case letters, numbers, andsymbols.

  5. ClickSave.

    The details page of the VM opens.

  6. ClickReset.

  7. Connect to the serial console.

  8. When prompted, enter your login information.

After the user has been created, replace the startup script with the startupscript that you stored in this section.

Setting up a local password usingpasswd on the VM

The following instructions describe how to set up a local password for auser on a VM so that the user can log on to theserial console of that VM using the specified password.

  1. Connect to the VM. Replaceinstance-namewith the name of your instance.

    gcloud compute sshinstance-name
  2. On the VM, create a local password with the following command. This actionsets a password for the user that you are logged in as.

    sudo passwd $(whoami)
  3. Follow the prompts to create a password.

  4. Next, log out of the instance andconnect to the serial console.

  5. Enter your login information when prompted.

Setting up a login on other serial ports

Login prompts are enabled on port 1 by default on all Linux public images that usesystemd service management. For Windows images, Login prompts are enabled onport 2 by default and managed by Device Manager. However, port 1 can often beoverwhelmed by logging data and other information being printed to the port.As an alternative, you can choose to enable a login prompt on another port, such as port 2(ttyS1), by executing the following command on your VM:

Linux

For Linux operating systems usingsystemd:

  • Enable the service temporarily until the next reboot:

    sudo systemctl start serial-getty@ttyS1.service
  • Enable the service permanently, starting with the next reboot:

    sudo systemctl enable serial-getty@ttyS1.service

Windows

For Windows operating systems:

  • Open Command Prompt as Administrator

  • Change the EMS Port from COM2 to COM1:

    bcdedit /emssettings EMSPORT:1 EMSBAUDRATE:9600
  • Reboot the VM

Understanding serial port numbering

Each virtual machine instance has four serial ports. For consistency with thegetSerialPortOutputAPI, each port is numbered 1 through 4. Linux and other similar systems numbertheir serial ports 0 through 3. For example, on many operating system images,thecorresponding devices are/dev/ttyS0 through/dev/ttyS3. Windows refers toserial ports asCOM1 throughCOM4. To connect to what Windows considersCOM3 and Linux considersttyS2, you would specify port 3. Usethe following table to help you figure out which port you want to connect to.

Virtual machine instance serial portsStandard Linux serial portsWindows COM ports
1/dev/ttyS0COM1
2/dev/ttyS1COM2
3/dev/ttyS2COM3
4/dev/ttyS3COM4

Note that many Linux images use port 1 (/dev/ttyS0) for logging messages fromthe kernel and system programs.

Sending a serial break

TheMagic SysRq key feature lets you perform low-level tasks regardless of the system'sstate. For example, you can sync file systems, reboot the instance,end processes, andunmount file systems using the Magic SysRq key feature.

To send a Magic SysRq command using a simulated serial break:

  1. Press theENTER key.
  2. Type~B (tilde, followed by uppercaseB).
  3. Type the Magic SysRq command.
Note: The Magic SysRq key is normally implemented by using PC keyboardscan codesbut there is no direct equivalent on a serial port. This is the recommendedmethod of accessing the Magic SysRq feature.

Viewing serial console audit logs

Compute Engine provides audit logs to track who has connected anddisconnected from an instance's serial console. To view logs, you must havepermissions for the Logs Vieweror be a project viewer or editor.

  1. In the Google Cloud console, go to theLogs Explorer page.

    Go to Logs Explorer

  2. Expand the drop-down menu and selectGCE VM Instance.
  3. In the search bar, typessh-serialport.googleapis.com and pressEnter.
  4. A list of audit logs appears. The logs describe connections anddisconnections from aserial console. Expand any of the entries to get more information.

For any of the audit logs, you can:

  1. Expand theprotoPayload property.
  2. Look formethodName to see activity this log applies to (either aconnection or disconnection request). For example, if this log tracks adisconnection from the serial console, the method name would say"google.ssh-serialport.v1.disconnect". Similarly, a connection log wouldsay"google.ssh-serialport.v1.connect". An audit log entry is recorded atthe beginning and end of each session on the serial console.

There are different audit log properties for different log types. For example,audit logs relating to connections have properties that arespecific to connection logs, while audit logs for disconnections havetheir own set of properties. There are certain audit log properties thatare also shared between both log types.

All serial console logs

The following table provides audit log properties and their values for allserial console logs:

PropertyValue
requestMetadata.callerIpThe IP address and port number from which the connection originated.
serviceNamessh-serialport.googleapis.com
resourceNameA string containing the project ID, zone, instance name, and serial port number to indicate which serial console this pertains to. For example,projects/myproject/zones/us-east1-a/instances/example-instance/SerialPort/2 is port number 2, also known as COM2 or /dev/ttyS1, for the instanceexample-instance.
resource.labelsProperties identifying the instance ID, zone, and project ID.
timestampA timestamp indicating when the session began or ended.
severityNOTICE
operation.idAn ID string uniquely identifying the session; you can use this toassociate a disconnect entry with the corresponding connection entry.
operation.producerssh-serialport.googleapis.com

Connection logs

The following table provides audit log properties and their values specific forconnection logs:

PropertyValue
methodNamegoogle.ssh-serialport.v1.connect
status.messageConnection succeeded.
request.serialConsoleOptionsAnyoptionsthat were specified with the request, including the serial port number.
request.@typetype.googleapis.com/google.compute.SerialConsoleSessionBegin
request.usernameThe username specified for this request. This is used to select the publickey to match.
operation.firstTRUE
status.codeFor successful connection requests, astatus.code value ofgoogle.rpc.Code.OK indicates that the operation completedsuccessfully without any errors. Because the enum value for this property is0, thestatus.code property is not displayed.However, any code that checks for astatus.code value ofgoogle.rpc.Code.OK will work as expected.

Disconnection logs

The following table provides audit log properties and their values specific fordisconnection logs:

PropertyValue
methodNamegoogle.ssh-serialport.v1.disconnect
response.durationThe amount of time, in seconds, that the session lasted.
response.@typetype.googleapis.com/google.compute.SerialConsoleSessionEnd
operation.lastTRUE

Failed connection logs

When a connection fails, Compute Engine creates an audit log entry. Afailed connection log looks very similar to a successful connection entry, buthas the following properties to indicate a failed connection.

PropertyValue
severityERROR
status.code

Thecanonical Google API error codethat best describes the error. The following are possible error codes that mightappear:

status.messageThe human-readable message for this entry.

Disabling interactive serial console access

You can disable interactive serial console access by changing metadata on thespecific instance or project, or by setting anOrganization Policy thatdisables interactive serial console access to all VM instances for one or moreprojects that are part of the organization.

Disabling interactive serial console on a particular instance or project

Project owners and editors, as well as users who have been granted thecompute.instanceAdmin.v1 role, can disable access to the serial console bychanging the metadata on the particular instance or project. Similar toenabling serial console access,set theserial-port-enable metadata toFALSE:

serial-port-enable=FALSE

For example, using the Google Cloud CLI, you can apply this metadatato a specific instance like so:

gcloud compute instances add-metadatainstance-name \    --metadata=serial-port-enable=FALSE

To apply the metadata to the project:

gcloud compute project-info add-metadata \    --metadata=serial-port-enable=FALSE

Disabling interactive serial console access through Organization Policy

If you have been granted theorgpolicy.policyAdmin role on the organization,you can set anorganization policythat prevents interactive access to the serial console, regardless of whetherinteractive serial console access is enabled on the metadata server. After theorganization policy is set, the policy effectively overrides theserial-port-enable metadata key,and no users of the organization or project can enable interactive serialconsole access. By default, this constraint is set toFALSE.

The constraint for disabling interactive serial console access is as follows:

compute.disableSerialPortAccess

Complete the following instructions to set this policy on the organization.After setting up a policy, you can grant exemptions on a per-project basis.

gcloud

To set the policy using the Google Cloud CLI, run theresource-manager enable-enforce command. Replaceorganization-id with yourorganization ID.For example,1759840282.

gcloud resource-manager org-policies enable-enforce \    --organizationorganization-id compute.disableSerialPortAccess

REST

To set a policy in the API, make aPOST request to the following URL. Replaceorganization-name with yourorganization name. For example,organizations/1759840282.

 POST https://cloudresourcemanager.googleapis.com/v1/organization-name:setOrgPolicy

The request body should contain apolicy object with the following constraint:

"constraint": "constraints/compute.disableSerialPortAccess"

For example:

 {   "policy":   {     "booleanPolicy":     {       "enforced": TRUE     },     "constraint": "constraints/compute.disableSerialPortAccess"   } }

The policy is immediately effective, so any projects under the organizationimmediately stop allowing interactive access to the serial console.

To temporarily disable the policy, use thedisable-enforce command:

gcloud resource-manager org-policies disable-enforce \    --organizationorganization-id compute.disableSerialPortAccess

Alternatively, you can make an API request where the request body sets theenforced parameter toFALSE:

{  "policy":  {    "booleanPolicy":    {      "enforced": FALSE    },    "constraint": "constraints/compute.disableSerialPortAccess"  }}

Setting the organization policy at the project level

You can set the same organizational policy on a per-project basis. Thisoverrides the setting at the organization level.

gcloud

To turn off enforcement of this policy for a specific project. Replaceproject-id with your project ID.

gcloud resource-manager org-policies disable-enforce \    --projectproject-id compute.disableSerialPortAccess

You can turn on enforcement of this policy by using theenable-enforcecommand with the same values.

REST

In the API, make aPOST request to the following URL to enable interactiveserial console access for the project, replacingproject-id with the project ID:

POST https://cloudresourcemanager.googleapis.com/v1/projects/project-id:setOrgPolicy

The request body should contain apolicy object with the followingconstraint:

"constraint": "constraints/compute.disableSerialPortAccess"

For example:

{  "policy":  {    "booleanPolicy":    {      "enforced": FALSE    },    "constraint": "constraints/compute.disableSerialPortAccess"  }}

Tips and tricks

  • If you are having trouble connecting using a standard SSH client, butgcloud compute connect-to-serial-port connects successfully, it might behelpful to rungcloud compute connect-to-serial-port with the--dry-runcommand-line option to see the SSH command that it would have run on yourbehalf, and compare the options with the command you are using.

  • If you're using a Windows VM with OS Login enabled and encounter anUNAUTHENTICATED error, verify that your public SSH keys have been posted to your project or instance metadata. To learn more, seeManaging SSH keys in metadata.

  • Setting the bit rate, also known as baud rate, you can set any bit rate youlike, such asstty 9600, but the feature normally forces the effective rate to115,200 bps (~11.5kB/sec). This is because many public images default toslow bitrates, such as 9,600 on the serial console, and would boot slowly.

  • Some OS images have inconvenient defaults on the serial port. For example,on CentOS 7, thestty icrnl default for the Enter key on the console is tosend aCR, also known as^M. The bash shell might maskthis until you try to set a password, at which point you might wonder why itseems stuck at thepassword: prompt.

  • Some public images have job control keys that are disabled by default if youattach a shell to a port in certain ways. Some examples of these keys include^Z and^C. Thesetsid command might fix this. Otherwise, if you see ajob control is disabled in this shell message, be careful not to runcommands that you will need to interrupt.

  • You might find it helpful to tell the system the size of the window you'reusing, so that bash and editors can manage it properly. Otherwise, you mightexperience odd display behavior because bash or editors attempt to manipulatethedisplay based on incorrect assumptions about the number of rows and columnsavailable. Use thestty rows Y cols X command andstty -a flag to seewhat the setting is. For example:stty rows 60 cols 120(if your window is 120 chars by 60 lines).

  • If, for example, you connect using SSH from machine A to machine B, and thento machine C, creating a nested SSH session, and you want to usetilde (~) commands to disconnect or send a serial break signal, you will needto addenough extra tilde characters to the command to get to the right SSH client. Acommand following a single tilde is interpreted by the SSH client onmachine A; a command following two consecutive tildes (Enter~~) isinterpreted by the client on machine B, and so forth. You only need to pressEnter one time because thatis passed all the way through to the innermost SSH destination. This is truefor any use of SSH clients that provide the tilde escape feature.

    If you lose track of how many tilde characters you need, press the Enterkey and then type tilde characters one at a time until the instance echoesthe tilde back. This echo indicates that you have reached the end of thechain and younow know that to send a tilde command to the most nested SSH client, youneed one less tilde than however many tildes you typed.

Advanced options

You can also use the following advanced options with the serial port.

Controlling max connections

You can set themax-connections property to control how many concurrentconnections can be made to this serial port at a time. The default andmaximum number of connections is 5. For example:

gcloud compute connect-to-serial-portinstance-name \    --portport-number \    --extra-args max-connections=3
ssh -iprivate-ssh-key-file -p 9600project-id.zone.instance-name.username.max-connections=3@ssh-serialport.googleapis.com

Setting replay options

By default, each time you connect to the serial console, you will receivea replay of the last 10 lines of data, regardless of whether the last 10 lineshave been seen by another SSH client. You can change this setting and controlhow many and which lines are returned by setting the following options:

  • replay-lines=N: SetN to the number of lines you want replayed. Forexample, ifN is 50, then the last 50 lines of the console output isincluded.
  • replay-bytes=N: Replays the most recentN bytes. You can also setN tonew which replays all output that has not yet been sent to any client.
  • replay-from=N: Replays output starting from an absolute byte indexthat you provide. You can get the current byte indexof serial console output by making agetSerialPortOutputrequest. If you setreplay-from, all other replay options are ignored.

With the Google Cloud CLI, append the following to yourconnect-to-serial-port command, whereN is the specified number of lines(or bytes or absolute byte index, depending on which replay option you areselecting):

--extra-args replay-lines=N

If you are using a third-party SSH client, provide this option in your SSHcommand:

ssh -iprivate-ssh-key-file -p 9600 myproject.us-central1-f.example-instance.jane.port=3.replay-lines=N@ssh-serialport.googleapis.com

You can also use a combination of these options as well. For example:

replay-lines=N andreplay-bytes=new
Replay the specified number of lines OR replay all output not previouslysent to any client, whichever is larger. The first client to connect with thisflag combination will see all the output that has been sent to the serialport, and clients that connect subsquently will only see the lastN lines. Examples:
gcloud compute connect-to-serial-portinstance-name--portport-number --extra-args replay-lines=N,replay-bytes=new
ssh -iprivate-ssh-key-file -p 9600project-id.zone.instance-name.username.replay-lines=N.replay-bytes=new@ssh-serialport.googleapis.com
replay-lines=N andreplay-bytes=M
Replay lines up to, but not more than, the number of lines or bytesdescribed by these flags, whichever is less. This option won't replay morethanN orM bytes.
gcloud compute connect-to-serial-portinstance-name--portport-number --extra-args replay-lines=N,replay-bytes=M
ssh -iprivate-ssh-key-file -p 9600project-id.zone.instance-name.username.replay-lines=N.replay-bytes=M@ssh-serialport.googleapis.com

Handling dropped output

The most recent 1 MiB of output for each serial port is always available andgenerally, your SSH client shouldn't miss any output from the serial port.If, for some reason, your SSH client stops accepting output for a period oftime but does not disconnect, and more than 1 MiB of new data is produced,your SSH client might miss some output. When your SSHclient is not accepting data fast enough to keep up with the output on theserial console port, you can set theon-dropped-output property to determinehow the console behaves.

Set any of the following applicable options with this property:

  • insert-stderr-note: Insert a note on the SSH client'sstderr indicatingthat output was dropped. This is the default option.
  • ignore: Silently drops output and does nothing.
  • disconnect: Stop the connection.

For example:

gcloud compute connect-to-serial-portinstance-name \    --portport-number \    --extra-args on-dropped-output=ignore
ssh -iprivate-ssh-key-file -p 9600project-id.zone.instance-name.username.on-dropped-output=ignore@ssh-serialport.googleapis.com

Enabling disconnect using exit or logout commands

You can enable disconnecting on exit or logout commands by setting theon-dtr-low property todisconnect when you connect to the serial console.

On the Google Cloud CLI, append the following flag to yourconnect-to-serial-port command:

--extra-args on-dtr-low=disconnect

If you are using a third-party SSH client, provide this option in your SSHcommand:

ssh -iprivate-ssh-key-file -p 9600 myproject.us-central1-f.example-instance.jane.port=3.on-dtr-low=disconnect@ssh-serialport.googleapis.com

Enabling thedisconnect option might cause your instance to disconnect one ormore times when you are rebooting the instance because the operating systemresets the serial ports while booting up.

Note: With some operating systems, this setting has no effecton serial port 1. However, it should work on ports 2 through 4 for mostoperating systems, and on port 1 for some systems.

The default setting for theon-dtr-low option isnone. If you use thedefault settingnone, you can reboot your instance without being disconnectedfrom the serial console, but the console won't disconnect through normalmeans such asexit orlogout commands, or normal key combinations likeCtrl+D.

What's next

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-12-15 UTC.