无法在浏览器中通过 SSH 连接到 Google Compute Engine 实例 [英] Cannot connect to Google Compute Engine instance via SSH in browser

查看:24
本文介绍了无法在浏览器中通过 SSH 连接到 Google Compute Engine 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过 ssh 连接到 GCE.显示连接失败,我们无法在端口 22 上连接虚拟机.

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

7 月 8 日 10:09:26 实例 sshd[10103]:错误:无法加载主机密钥:/etc/ssh/ssh_host_ed25519_key

Jul 8 10:09:26 Instance sshd[10103]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

7 月 8 日 10:09:27 实例 sshd[10103]:不允许来自 0.0.0.0 的用户名,因为未在 AllowUsers 中列出

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

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

昨天运行正常,但今天显示此错误.我是 GCE 的新手.有什么建议吗?

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

推荐答案

UPDATE

我想发布此更新是为了说明 2016 年 6 月发布了一项新功能,您可以在其中启用对串行控制台的交互式访问,以便您可以更轻松地对无法正常启动或无法访问的实例进行故障排除.请参阅与串行控制台交互以了解更多信息.

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.

看起来您已经在 /etc/ssh/sshd_config 配置文件中添加了 AllowUsers.

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. 首先,为您的实例磁盘拍摄快照,以防万一发生丢失或损坏的情况,您可以恢复您的磁盘.

  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.

在开发人员控制台中,单击您的实例.取消勾选删除实例时删除启动盘,然后删除实例.启动磁盘将保留在磁盘"下,现在您可以将磁盘附加到另一个实例.您也可以使用 gcloud 命令执行此步骤:

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

  • 现在将磁盘作为附加磁盘附加到运行状况良好的实例.您可以通过开发者控制台或使用 gcloud 命令执行此操作:

    $ gcloud compute instances attach-disk EXAMPLE-INSTANCE --disk DISK --zone ZONE
    

  • 通过 SSH 连接到您的健康实例.

  • 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
    

  • 其中 google-persistent-disk-1 是磁盘的名称

    1. 编辑 sshd_config 配置文件并删除 AllowUsers 行并保存.

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

    $ sudo nano /mnt/tmp/etc/ssh/sshd_config
    

  • 现在取出磁盘:

  • Now unmout the disk:

    $ sudo umount /mnt/tmp
    

  • 将其从 VM 实例中分离.这可以通过开发者控制台或使用以下命令来完成:

  • 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.

    这篇关于无法在浏览器中通过 SSH 连接到 Google Compute Engine 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆