Cannot connect to Google Compute Engine instance v

2019-07-12 21:36发布

I cannot connect to GCE via ssh. It is showing Connection Failed, and we are unable to connect VM on port 22.

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] – Error Message

Yesterday it was working fine, but today it shows this error. I am new to GCE. Any suggestions?

1条回答
我想做一个坏孩纸
2楼-- · 2019-07-12 22:19

UPDATE

I'd like to post this update to mention that on June 2016 a new feature is released where you can enable interactive access to the serial console so you can more easily troubleshoot instances that are not booting properly or that are otherwise inaccessible. See Interacting with the Serial Console for more information.

-----------------------------------------------------------------------------------

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:

  1. First of all, take a snapshot of your instance’s disk, in case if a loss or corruption happens you can recover your disk.

  2. 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 using gcloud command:

    $ gcloud compute instances delete NAME --keep-disks all
    
  3. 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
    
  4. SSH into your healthy instance.

  5. Determine where the secondary disk lives:

    $ ls -l /dev/disk/by-id/google-*
    
  6. 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

  1. Edit sshd_config configuration file and remove AllowUsers line and save it.

    $ sudo nano /mnt/tmp/etc/ssh/sshd_config
    
  2. Now unmout the disk:

    $ sudo umount /mnt/tmp
    
  3. 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
    
  4. Now create a new instance using your fixed boot disk.

查看更多
登录 后发表回答