在 GCP 中更改 SSH 端口导致拒绝连接

在 GCP 中更改 SSH 端口导致拒绝连接

我使用 ssh 登录计算引擎实例。然后我将 ssh 的端口更改为 12345。/etc/ssh/sshd_config我保存它并使用 重新启动服务systemctl restart sshd

接下来,当我注销并再次登录时,会出现如下消息:

kex_exchange_identification: read: Connection reset by peer
Connection reset by xxx.xxx.xxx.xxx port 12345

我用端口 22 尝试了一下,结果是一样的:

kex_exchange_identification: read: Connection reset by peer
Connection reset by xxx.xxx.xxx.xxx port 22

然后我尝试使用自定义端口在浏览器中登录 Google Cloud Console。它也没有用。弹出窗口显示以下内容:

Connection failed
You cannot connect to the VM instance because of an unexpected error. Wait a few moments and then try again.

当我无法通过 SSH 和 Google Console 连接时,如何访问我的虚拟机?

答案1

在更改 sshd_config 中的端口之前,您是否在服务器防火墙中启用了 12345 端口?

如果服务器上的端口 12345 被阻止,您可能会收到此类错误。

答案2

如果上述方法失败,您还可以尝试为虚拟机启用“串行控制台”。然后打开虚拟机详细信息,您将在那里看到串行控制台登录选项(至少在撰写本文时)。

由于我把自己锁在外面但却成功了,所以希望它能帮助其他人!

相关内容