重启后无法通过 SSH 访问 Google Cloud 服务器

重启后无法通过 SSH 访问 Google Cloud 服务器

我正在学习配置 Debian 服务器并熟悉常用命令行。

但是,reboot在 SSH 中执行该命令后,我后续的 SSH 连接被拒绝,并且我完全无法访问服务器。

我能够连接到ping服务器。我也尝试通过 Google 云界面重新启动,但仍然无法成功连接。

将此作为云服务器,我无法对该服务器进行任何物理访问。我看到的解决方案似乎是重新配置 SSH 设置,如果不登录就无法配置。

我现在有哪些可能的替代方案,或者重新创建新实例是唯一的解决方案?

答案1

最好的选择是使用 gcloud 控制台手动创建密钥:

thufir@mordor:~$ 
thufir@mordor:~$ gcloud compute config-ssh
WARNING: The private SSH key file for Google Compute Engine does not exist.
WARNING: You do not have an SSH key for Google Compute Engine.
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/thufir/.ssh/google_compute_engine.
Your public key has been saved in /home/thufir/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:ioreurewiopruweoiprwe thufir@mordor
The key's randomart image is:
+---[RSA 2048]----+
.......
|                 |
|                 |
+----[SHA256]-----+

Updated [https://www.googleapis.com/compute/v1/projects/<project>].
You should now be able to use ssh/scp with your instances.
For example, try running:

  $ ssh <instance>.<location>.<project>

thufir@mordor:~$ 
thufir@mordor:~$ ssh <instance>.<location>.<project>
The authenticity of host 'compute.<####> (<ip address>)' can't be established.
ECDSA key fingerprint is SHA256:<fingerprint?>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'compute.<####>' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

$ 
$ 
$ whoami
thufir
$ pwd
/home/thufir
$ exit
Connection to <ip address> closed.
thufir@mordor:~$ 

来源:

https://askubuntu.com/questions/803908/

也可以看看:

如何为 Google 云计算 VPS 附加带有 JSON 的 SSH 密钥?

答案2

我认为Google给出了一个相当全面的解决SSH错误的解决方案列表,请参考这里

IMO,您可能错误地设置了 SSH 密钥,或者配置错误iptables

答案3

晚安,这件事刚刚发生了 cmg tbm,我想你应该已经修复或重新配置了你的 vps,但是对于那些面临这个问题的人,我能够通过端口 443 连接,之后运行 nano 命令 /etc/ssh/ sshd_config 并取消注释#Port 22 行,只取#

在此输入图像描述

答案4

  1. 在 GCP 上,查看您的实例然后对其进行编辑。
  2. 在“远程访问”下启用连接到串行端口。
  3. 滚动到页面底部并单击“保存”。
  4. 再次查看您的实例,这次在“远程访问”下,您将可以选择“连接到串行控制台”。这样,即使您的 SSH 失败(通常是由于 /etc/network/interfaces 文件配置错误),您也可以访问实例的命令提示符。
  5. 连接到串行控制台需要您登录现有帐户。因此,请记住passwd在乱搞网络之前先设置密码。

相关内容