ssh - GCP Compute-engine ssh 仅在文件内部失败
问题描述
我正在尝试编写启动 VM、运行命令然后停止它的脚本。
代码是(为简洁起见,省略了项目和区域):
gcloud compute instances start instance-1
gcloud compute ssh user@instance-1 --command 'echo check-ssh' -- -vvv
gcloud compute instances stop instance-1
当我在终端中运行这些步骤时,一切都很顺利,但是当我通过文件运行它时,ssh 命令失败,我得到:
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f 31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 34.68.81.200 is address
debug2: ssh_connect_direct
debug1: Connecting to 34.68.81.200 [34.68.81.200] port 22.
debug1: connect to address 34.68.81.200 port 22: Connection refused
ssh: connect to host 34.68.81.200 port 22: Connection refused
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
实例操作系统是 ubuntu 20.4。
可能与此问题有关的东西,当我尝试通过终端连接到 root 用户时,我得到了同样的错误。
有人知道有什么区别吗?我该如何解决?
解决方案
当您请求 GCP 计算实例的 gcloud 计算实例启动时,您实际上是在请求它启动,而不是它实际上已经启动。如果您随后转身执行 SSH 请求,则 VM 可能尚未达到准备接收 SSH 请求的内部状态。尝试在您的 VM 启动和 SSH 访问之间设置一个睡眠延迟(比如...... 5 分钟)......看看这是否会改变故事。
也可以看看:
推荐阅读
- python - sqlAlchemy 中的 ormSession - 在这种情况下如何执行读取和更新?
- javascript - 如何遍历这些输入字段但每个输入都有自己的状态?
- java - 我收到以下代码的“第 9 行:错误:找不到符号”错误:已排序数组的平方
- c# - 将 API 响应对象转换为 List
- wso2 - WSO2IS-5.7.0 OIDC SSO 注销没有 id_token_hint
- apache-spark - spark-shell 命令给出 ERROR Shell:397 - 无法在 hadoop 二进制路径 java.io.IOException 中找到 winutils 二进制文件:
- c++ - 如何有效地将 VkDispatchIndirectCommand 字段提升为 subgroupSize 的倍数
- c - 警告 C4047:“int **”与“int[2][4]”的间接级别不同
- java - 分页 JMS 队列
- opencart - htaccess seo问题