Unable to connect Google Compute Engine instance via SSH in browser
It looks like you've added AllowUsers
in /etc/ssh/sshd_config
configuration file.
To resolve this issue, you'll need to attach the boot disk of your VM instance to a healthy instance as the second disk. Mount it, edit the configuration file and fix the issue.
Here are the steps you can take to resolve the issue:
First of all, take a snapshot of your instance’s disk, in case if a loss or corruption happens you can recover your disk.
In the Developers Console, click on your instance. Uncheck
Delete boot disk when instance is deleted
and then delete the instance. The boot disk will remain under “Disks”, and now you can attach the disk to another instance. You can also do this step usinggcloud
command:$ gcloud compute instances delete NAME --keep-disks all
Now attach the disk to a healthy instance as an additional disk. You can do this through the Developers Console or using the
gcloud
command:$ gcloud compute instances attach-disk EXAMPLE-INSTANCE --disk DISK --zone ZONE
SSH into your healthy instance.
Determine where the secondary disk lives:
$ ls -l /dev/disk/by-id/google-*
Mount the disk:
$ sudo mkdir /mnt/tmp $ sudo mount /dev/disk/by-id/google-persistent-disk-1-part1 /mnt/tmp
Where google-persistent-disk-1
is the name of the disk
Edit
sshd_config
configuration file and removeAllowUsers
line and save it.$ sudo nano /mnt/tmp/etc/ssh/sshd_config
Now unmout the disk:
$ sudo umount /mnt/tmp
Detach it from the VM instance. This can be done through the Developers Console or using the command below:
$ gcloud compute instances detach-disk EXAMPLE-INSTANCE --disk DISK
Now create a new instance using your fixed boot disk.
Related videos on Youtube
Rahul Singh
Updated on September 18, 2022Comments
-
Rahul Singh over 1 year
i am new to google cloud,i just deployed my first instance it was working fine till yesterday, i used last time to set email server using this tutorial email server, but now i am unable to connect ssh in browser and also with google cloud sdk in terminal.
Website is running fine,I don't know what happened Please help
the error message in browser
Connection Failed, and we are unable to connect VM on port 22.
the error message in terminal
Warning: Permanently added 'xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts. Permission denied (publickey). ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
And serial console output its shows
Jul 8 10:09:26 Instance sshd[10103]: error: Could not load host key:/etc/ssh/ssh_host_ed25519_key Jul 8 10:09:27 Instance sshd[10103]: User username from 0.0.0.0 not allowed because not listed in AllowUsers Jul 8 10:09:27 Instance sshd[10103]: input_userauth_request: invalid user username [preauth] Jul 8 10:09:27 Instance sshd[10103]: Connection closed by 0.0.0.0 [preauth] –
-
Rahul Singh almost 9 yearsi am new to it i don't know how to mount and edit can you provide me link for tutorials anyway thanks hope it works
-
Kamran almost 9 yearsI've updated my answer with adding the steps you'll need to take to resolve the issue.
-
Misha Brukman almost 9 years@RahulSingh - Great to hear that your issue has been solved! Can you please accept this answer so that (a) credit is given where it’s due, and (b) the question is marked as closed? Thanks.