You can connect to your VM using the 'SSH' button in the GUI Console next to the instance in the list of instances, which will open a browser window and a terminal session to the instance.
If you would like to connect via SSH client on the command-line, you can use gcloud tool.
'gcloud compute ssh example-instance'
Please see this link for more information.
It will prompt you to create SSH keys and then connect to the instance.
Another option is to manually add the SSH keys to the instance's metadata as described in this link which you can do via gcloud or manually via Google Cloud console.
The default ssh authentication for GCE instance is public key authentication and not password based. Moreover, for security reasons, most of the standard Google images do not provide the ability to connect directly as root. The instance creator and any users that were added using the metadata sshKeys value are automatically administrators to the account, with the ability to run sudo without requiring a password. Although it is not recommended, you need to create a startup script which will reset your root password which you can then use.
- Go to the VM instances page in Google Cloud Platform console.
- Click on the instance for which you want to add a startup script.
- Click the Edit button at the top of the page.
- Click on ‘Enable connecting to serial ports’
- Under Custom metadata, click Add item.
- Set 'Key' to 'startup-script' and set 'Value' to this script:
echo 'root:PASSWORD' | chpasswd
- 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.
- Click on 'Connect to serial port' in the page.
- In the new window, you might need to wait a bit and press on Enter of your keyboard once; then, you should see the login prompt.
- Login using the root and PASSWORD you provided.