我正在学习配置 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/
也可以看看:
答案2
我认为Google给出了一个相当全面的解决SSH错误的解决方案列表,请参考这里。
IMO,您可能错误地设置了 SSH 密钥,或者配置错误iptables
。
答案3
答案4
- 在 GCP 上,查看您的实例然后对其进行编辑。
- 在“远程访问”下启用连接到串行端口。
- 滚动到页面底部并单击“保存”。
- 再次查看您的实例,这次在“远程访问”下,您将可以选择“连接到串行控制台”。这样,即使您的 SSH 失败(通常是由于 /etc/network/interfaces 文件配置错误),您也可以访问实例的命令提示符。
- 连接到串行控制台需要您登录现有帐户。因此,请记住
passwd
在乱搞网络之前先设置密码。