1

My GCP instance is not booting peoperly, I am trying to connect using serial port 1 and key but it asks password which I never set. I enabled it gcloud compute instances add-metadata teyeprodv1 --metadata serial-port-enable=1 gcloud compute connect-to-serial-port user@instance-name --ssh-key-file ~/.ssh/key.pem --zone us-central1-a

Second command ask username and password. I know username but not password. enter image description here

2

After enabling serial port, you should create a startup script to create a user which will allow you to connect to the VM.

  1. On your VM instance, click the Edit button at the top of the page.
  2. Under Custom metadata, click Add item.
  3. Set 'Key' to 'startup-script' and set 'Value' to this script:

    #! /bin/bash
    adduser username
    echo 'username:password' | chpasswd
    usermod -aG google-sudoers test

  4. Click Save and then click RESET on the top of the page. You might need to wait for some time for the instance to reboot.

  5. Click on 'Connect to serial port' in the page.

  6. In the new window, you might need to wait a bit and press Enter; then, you should see the login prompt.

  7. Login using the USERNAME and PASSWORD you provided.

  • Thanks Ivan for reply. Please keep in touch with me for fixing the issue. I tried but no to avail. How can I verify if user is created or not. I mean script run successfully or not.It is prompting Login incorrect. – user527759 Jun 14 at 10:50
  • The startup script may vary depending on the OS. Which OS are you using?? – Ivan Jun 14 at 10:54
  • I am using ubuntu 16.04. – user527759 Jun 14 at 10:55
  • Just tested in 16.04, the script is good. Make sure to set key 'startup-script' and value the script from #3. After that you should save and reset the VM. – Ivan Jun 14 at 11:00
  • I also tested the script in Ubuntu 16.04, It ask password. Adding user itsec' ... Adding new group itsec' (1004) ... Adding new user itsec' (1003) with group itsec' ... Creating home directory /home/itsec' ... Copying files from /etc/skel' ... Enter new UNIX password: – user527759 Jun 14 at 11:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.