简体   繁体   English

GCE - 我们无法连接到端口 22 上的虚拟机

[英]GCE - We are unable to connect to the VM on port 22

I'm having the following error when I try to connect via SSH to my instance on Google Compute Engine.当我尝试通过 SSH 连接到我在 Google Compute Engine 上的实例时出现以下错误。

Connection Failed. We are unable to connect to the VM on port 22.

Steps I did to get that error我为得到该错误所做的步骤

  • Created a new instance using an Ubuntu template.使用 Ubuntu 模板创建了一个新实例。
  • Connected via SSH and installed all my required apps.通过 SSH 连接并安装了我需要的所有应用程序。
  • Deleted the instance but without deleting the boot disk when instance is deleted.删除实例但未删除实例时删除启动磁盘。
  • Created a new custom image using the boot disk of the deleted instance.使用已删除实例的启动磁盘创建新的自定义映像。
  • started a new instance using the custom image.使用自定义图像启动了一个新实例。
  • Click on the SSH link from the GCE console.从 GCE 控制台单击 SSH 链接。

This is the Serial console output for the instance.这是实例的串行控制台 output。

[    0.338119] Loading compiled-in X.509 certificates
[    0.339445] Loaded X.509 cert 'Magrathea: Glacier signing key: e09b1e7e9841e9cfef256b70ab210562dab1ef68'
[    0.341236] registered taskstats version 1
[    0.342183] Key type trusted registered
[    0.342872] Key type encrypted registered
[    0.343453] AppArmor: AppArmor sha1 policy hashing enabled
[    0.344592] ima: No TPM chip found, activating TPM-bypass!
[    0.345433] evm: HMAC attrs: 0x1
[    0.345974]   Magic number: 0:206:635
[    0.346956] rtc_cmos 00:00: setting system clock to 2016-01-17 13:37:20 UTC (1453037840)
[    0.348137] BIOS EDD facility v0.16 2004-Jun-25, 0 devices found
[    0.349722] EDD information not available.
[    0.524305] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input2
[    0.525744] md: Waiting for all devices to be available before autodetect
[    0.526718] md: If you don't use raid, use raid=noautodetect
[    0.527798] md: Autodetecting RAID arrays.
[    0.528396] md: Scanned 0 and added 0 devices.
[    0.529008] md: autorun ...
[    0.529414] md: ... autorun DONE.
[    0.529988] VFS: Cannot open root device "sda1" or unknown-block(0,0): error -6
[    0.530970] Please append a correct "root=" boot option; here are the available partitions:
[    0.532106] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    0.533250] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.19.0-43-generic #49~14.04.1-Ubuntu
[    0.534451] Hardware name: Google Google, BIOS Google 01/01/2011
[    0.535409]  ffffea0002edc240 ffff88012af0fdb8 ffffffff817afcd5 00000000000011ba
[    0.536095]  ffffffff81a7c8b8 ffff88012af0fe38 ffffffff817a9b15 ffff88012af0fdd8
[    0.536095]  ffffffff00000010 ffff88012af0fe48 ffff88012af0fde8 ffff88012af0fe38
[    0.536095] Call Trace:
[    0.536095]  [<ffffffff817afcd5>] dump_stack+0x45/0x57
[    0.536095]  [<ffffffff817a9b15>] panic+0xc1/0x1f5
[    0.536095]  [<ffffffff81d3e5f3>] mount_block_root+0x210/0x2a9
[    0.536095]  [<ffffffff81d3e822>] mount_root+0x54/0x58
[    0.536095]  [<ffffffff81d3e993>] prepare_namespace+0x16d/0x1a6
[    0.536095]  [<ffffffff81d3e304>] kernel_init_freeable+0x1f6/0x20b
[    0.536095]  [<ffffffff81d3d9a7>] ? initcall_blacklist+0xc0/0xc0
[    0.536095]  [<ffffffff817a01d0>] ? rest_init+0x80/0x80
[    0.536095]  [<ffffffff817a01de>] kernel_init+0xe/0xf0
[    0.536095]  [<ffffffff817b7658>] ret_from_fork+0x58/0x90
[    0.536095]  [<ffffffff817a01d0>] ? rest_init+0x80/0x80
[    0.536095] Kernel Offset: 0x0 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
[    0.536095] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

So my question is how can I connect via SSH to my instance and how to make sure it doesn't happen again when I create a new custom image.所以我的问题是如何通过 SSH 连接到我的实例,以及如何确保在创建新的自定义图像时它不会再次发生。

Thanks.谢谢。

I had the same issue with one of my GCP VM instance.我的 GCP VM 实例之一也遇到了同样的问题。 My solution was:我的解决方案是:

  1. Shut down the instance关闭实例
  2. Click 'Edit' for the instance单击实例的“编辑”
  3. Under 'Custom Metadata' section, add 'startup-script' key, with value:在“自定义元数据”部分下,添加“启动脚本”键,其值:
#! /bin/bash
sudo ufw allow 22
  1. Click 'Save'点击“保存”
  2. Start the instance again, and SSH into it再次启动实例,并通过 SSH 进入它

Hope it helps!希望能帮助到你!

重启你的实例。它对我有用。

opening google cloud - go to your VM Instance - click Stop - click start than its working well ...:)打开谷歌云 - 转到您的 VM 实例 - 单击停止 - 单击开始比它运行良好...:)

This issue with SSH terminal , because you directly close ssh terminal , you musch tyoe " " close " command than cancel the broswer's tab after you won't appear that issue :) SSH 终端的这个问题,因为您直接关闭了 ssh 终端,所以在您不会出现该问题之后,您必须使用“关闭”命令而不是取消浏览器的选项卡:)

Good Luck .祝你好运 。

Please follow the documentation :请遵循 文档

  1. create a new firewall rule and delete all existing firewall创建一个新的防火墙规则并删除所有现有的防火墙
  2. stop the vm停止虚拟机
  3. restart your vm and try to run SSH重新启动您的虚拟机并尝试运行 SSH

It will work.它会起作用。

Just add one more firewall rule which can allow ssh.只需再添加一项允许 ssh 的防火墙规则。 You can name it "default-allow-ssh"您可以将其命名为“default-allow-ssh”

  • Network - default网络 - 默认
  • Priority - 65534优先级 - 65534
  • Direction - Ingress方向 - 入口
  • Action on match - Allow匹配操作 - 允许
  • Source filters: IP ranges - 0.0.0.0/0源过滤器:IP 范围 - 0.0.0.0/0
  • Protocols and ports - tcp:22协议和端口 - tcp:22
  • Enforcement - Enabled强制执行 - 已启用
  • Insights - None洞察力 - 无

This issue is due to firewall setting.这个问题是由于防火墙设置。 If GCE Instance is created in default VPC, with default firewall it will deny all incoming traffic.如果 GCE 实例是在默认 VPC 中创建的,使用默认防火墙它将拒绝所有传入流量。 We need to explicitly create firewall rule which will allow traffic on port 22 Explained in detail in below video https://youtu.be/3HyEzL6fm-M我们需要明确创建防火墙规则,允许端口 22 上的流量在下面的视频https://youtu.be/3HyEzL6fm-M中详细解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM