我正在學習配置 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
在亂搞網路之前先設定密碼。