Unable to SSH to GCE instance

1,788 views
Skip to first unread message

Parichat Chonwiharnphan

unread,
Jun 24, 2018, 11:30:08 AM6/24/18
to gce-discussion
I try to connect to GCE instance with SSH web console, serial connection, gcloud command, and other SSH client.

None of them work.

With web console, it stuck at "Transferring SSH keys to the VM.".

With gcloud command and SSH directly, I got "Server refused our key"

And serial connection asked for username/password which I don't have

I also try to reset metadata and enable OS login.

This didn't work too.

Can anybody help me with this?

Parichat Chonwiharnphan

unread,
Jun 24, 2018, 11:30:22 AM6/24/18
to gce-discussion
I tried connect to SSH from web console, gcloud command, serial connection, and directly ssh into it.

None of them work.

With web console, there's no error but it stuck with this message "Transferring SSH keys to the VM".

With gcloud command, it says server refused the key.
With serial connection, it asked for username and password, which I don't have.

Before this happens, I got some error about not enough space on my Jupyter notebook.
So I increased the size of boot disk from 10 GB to 40 GB.

I also try remove project's metadata and enable OS login. No luck too.

Karthick (Cloud Platform Support)

unread,
Jun 24, 2018, 6:40:11 PM6/24/18
to gce-dis...@googlegroups.com
Hello,

At this point I suggest you to recreate the SSH keys file using serial console. Please backup and then remove 'authorized_key' folder as below:
$ cd $HOME/.ssh
$ sudo cp -p authorized_keys /root
$ sudo rm -r authorized_keys

Then, exit the SSH session and connect again. It will transfer SSH keys again to the VM.

And since you don’t have a root password for the serial console, you could use an startup script to add it to your instance, the script would be like this:

1. Go to the VM instances page in Google Cloud Platform console.
2. Click on the instance for which you want to add a startup script.
3. Click the Edit button at the top of the page.
4. Click on ‘Enable connecting to serial ports’
5. Under Custom metadata, click Add item.
6. Set 'Key' to 'startup-script' and set 'Value' to this script:
#! /bin/bash
useradd -G sudo USERNAME
echo 'USERNAME:PASSWORD' | chpasswd
7. 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.
8. Click on 'Connect to serial port' in the page.
9. 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.
10. Login using the USERNAME and PASSWORD you provided.

If you are still facing issue, you can send me in private message the verbosity output of gcloud command as shown below  when trying to attempt ssh, to troubleshoot further

gcloud compute ssh INSTANCENAME --zone ZONE --verbosity=debug

Also, the output ("ps aux | grep ssh) from serial console to check if the ssh daemon is running.


I hope this helps. 

Ravina Gelda

unread,
Jun 24, 2020, 12:13:02 PM6/24/20
to gce-discussion
Hi,
 I tried the below proceed, but I am stuck at login step, as I do not seem to have correct login and password, how can i get my login password?

pralove

unread,
Jun 25, 2020, 7:45:09 PM6/25/20
to gce-discussion
If you want to change your user password in the GCP vm instance, 

You could log in to the virtual machine instance form your GCP cloud shell using the command:

gcloud compute ssh INSTANCE-NAME --zone=ZONE

Then, you could change the password of your user using the command:

   sudo passwd USER
   New password: 
   Retype new password: 
   
I hope this helps. Thanks.

Julio Cesar Maia Gonçalves

unread,
Jan 8, 2021, 3:53:24 PM1/8/21
to gce-discussion
this case is resolved ? i have the same problem!

Lucas (Cloud Platform Support)

unread,
Jan 11, 2021, 12:05:03 PM1/11/21
to gce-discussion
Hello,

Please be advised that Google Groups is not a place for troubleshooting. If you want a wider range of assistance, I would suggest you pose this question on StackOverFlow.

Please follow the troubleshooting steps provided by Karthick and Pralove in order to get new SSH Keys and a new password when logging into the virtual machine instance from your GCP cloud shell. 

Regards,
Reply all
Reply to author
Forward
0 new messages