简体   繁体   English

谷歌云平台修复 SSH

[英]Google Cloud Platform fix SSH

I have a problem with SSH access on my google compute engine .我的谷歌计算引擎上的SSH访问有问题。 I made a server, set up the application on it and configured the domain and everything works.我制作了一台服务器,在其上设置了应用程序并配置了域,一切正常。 After a few days when I wanted to approach her to make changes my SSH didn't work.几天后,当我想接近她进行更改时,我的 SSH 没有工作。 I have one assumption I was turning on firewall and I didn't add a rule for SSH , maybe that's a problem?我有一个假设我正在打开防火墙并且我没有为 SSH 添加规则,也许这是个问题? But how to access the machine now and enable it?但是现在如何访问机器并启用它呢?

Thanks in advance.提前致谢。

To solve your issue you can connect to your VM instance via serial console.要解决您的问题,您可以通过串行控制台连接到您的 VM 实例。 Before connecting to the VM via serial console check if you enabled connections to your VM instance at GCP Firewall .在通过串行控制台连接到 VM 之前,请检查您是否在GCP Firewall启用了与 VM 实例的连接。

Please have a look at the step by step instructions below:请查看以下分步说明:

  1. Enable serial console connection with gcloud command:使用gcloud命令启用串行控制台连接

     gcloud compute instances add-metadata NAME_OF_YOUR_VM_INSTANCE \ --metadata serial-port-enable=TRUE

or go to Compute Engine -> VM instances -> click on NAME_OF_YOUR_VM_INSTANCE -> click on EDIT -> go to section Remote access and check Enable connecting to serial ports或 go 到Compute Engine -> VM instances -> 点击NAME_OF_YOUR_VM_INSTANCE -> 点击EDIT -> go 到Remote access部分并选中Enable connecting to serial ports

  1. Create temporary user and password to login: shutdown your VM and set a startup script by adding at the section Custom metadata key startup-script and value:创建临时用户和密码以登录:关闭您的虚拟机并通过在Custom metadatastartup-script和值部分添加来设置启动脚本

     #:/bin/bash useradd --groups google_sudoers tempuser echo "tempuser:password" | chpasswd

and then start your VM.然后启动你的虚拟机。

  1. Connect to your VM via serial port with gcloud command:使用gcloud命令通过串口连接到你的虚拟机

     gcloud compute connect-to-serial-port NAME_OF_YOUR_VM_INSTANCE

    or go to Compute Engine -> VM instances -> click on NAME_OF_YOUR_VM_INSTANCE -> and click on Connect to serial console或 go 到Compute Engine -> VM instances -> 点击NAME_OF_YOUR_VM_INSTANCE -> 并点击Connect to serial console

  2. Check what went wrong.检查出了什么问题。

  3. Disable access via serial port with gcloud command:使用gcloud命令禁用通过串口的访问

     gcloud compute instances add-metadata NAME_OF_YOUR_VM_INSTANCE \ --metadata serial-port-enable=FALSE

or go to Compute Engine -> VM instances -> click on NAME_OF_YOUR_VM_INSTANCE -> click on EDIT -> go to section Remote access and uncheck Enable connecting to serial ports .或 go 到Compute Engine -> VM instances -> 点击NAME_OF_YOUR_VM_INSTANCE -> 点击EDIT -> go 到Remote access部分并取消选中Enable connecting to serial ports Keep in mind that accordingly to the documentation Interacting with the serial console :请记住,根据文档Interacting with the serial console

Caution : The interactive serial console does not support IP-based access restrictions such as IP whitelists.注意:交互式串行控制台不支持基于 IP 的访问限制,例如 IP 白名单。 If you enable the interactive serial console on an instance, clients can attempt to connect to that instance from any IP address.如果您在实例上启用交互式串行控制台,客户端可以尝试从任何 IP 地址连接到该实例。 Anybody can connect to that instance if they know the correct SSH key, username, project ID, zone, and instance name.如果知道正确的 SSH 密钥、用户名、项目 ID、区域和实例名称,任何人都可以连接到该实例。 Use firewall rules to control access to your network and specific ports.使用防火墙规则来控制对您的网络和特定端口的访问。

In addition, have a look at 3rd party example Resolving getting locked out of a Compute Engine .此外,请查看 3rd party example Resolving getting locked out of a Compute Engine

If you weren't able to connect via serial console check logs:如果您无法通过串行控制台检查日志进行连接

  1. Go to Compute Engine -> VM instances -> click on NAME_OF_YOUR_VM -> at the VM instance details find section Logs and click on Serial port 1 (console) Go 到Compute Engine -> VM instances -> 点击 NAME_OF_YOUR_VM -> 在VM instance details找到Logs部分,然后点击Serial port 1 (console)
  2. Reboot your VM instance again.再次重新启动您的 VM 实例。
  3. Check full boot log for any errors or/and warnings.检查完整的启动日志是否有任何错误或/和警告。

If you found errors/warning related to disk space you can try to resize it accordingly to the documentation Resizing a zonal persistent disk , also accordingly to the article Recovering an inaccessible instance or a full boot disk :如果您发现与磁盘空间相关的错误/警告,您可以尝试根据Resizing a zonal persistent disk文档调整其大小,也可以参考Recovering an inaccessible instance or full boot disk文章:

If nothing helped , try to follow other recommendations from the documentation Troubleshooting SSH and update your question with your attempts.如果没有任何帮助,请尝试遵循文档故障排除 SSH中的其他建议,并根据您的尝试更新您的问题。

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

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