ssh - 如何从 Circleci ssh 到 GCP 计算引擎实例?

标签 ssh google-cloud-platform continuous-delivery circleci-2.0

我正在使用circleci 2.0,我试图让circleci通过ssh进入gcp实例并使用此命令启动部署脚本

sudo /opt/google-cloud-sdk/bin/gcloud compute ssh instance-1 
--command=/home/deploy_staging.sh --zone=us-east1-b

从我的本地计算机执行此操作效果很好,但是当我尝试从 Circleci 执行此操作时,我收到此错误:

WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Too long with no output (exceeded 10m0s)

显然是 ssh 问题。我读到了一些关于将 ssh key 放入 gcp 实例中的内容,并且我已将本地计算机的 ssh key 放在那里,但这仍然不起作用。

最佳答案

gcloud \
  --quiet \
  --project="${PROJECT}" \
  compute ssh "${INSTANCE_NAME}" \
  --zone "${ZONE}" \
  --strict-host-key-checking=no \
  --command "echo works"

--quiet 就是您所需要的,如果 key 不可用,它将生成一个 key 。我将其与服务帐户一起使用。

WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/google_compute_engine.
Your public key has been saved in /root/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:un2aZmExTGVD0KvebEVqAujrlXoAb0u7jO3Z5boCWaA root@581dc589b7fa
The key's randomart image is:
+---[RSA 2048]----+
|        .==      |
|  .     ....     |
| . . . o   .     |
|E . o . + . .    |
|   *   .S+ o     |
|  o *  o= o .    |
|   + =+o.* .     |
|   +==.=+.=      |
|  .oO+===+       |
+----[SHA256]-----+
WARNING: Using OS Login user [sa_102839341411404994442] instead of default user [root]

关于ssh - 如何从 Circleci ssh 到 GCP 计算引擎实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47808245/

相关文章:

linux - 当其父 sshd 进程终止时,进程会发生什么?

python-3.x - 属性错误 : module 'google.cloud.monitoring_v3.types' has no attribute 'MetricDescriptor'

shared-libraries - 与内部图书馆的持续集成

git - 在单一存储库中构建微服务的最佳策略是什么?

python - 在 ssh session 中启用 tty

ssh - 如何配置httpclient以使用远程DNS解析?

linux - 奇怪的差异行为

python - 谷歌云函数抛出奇怪的错误

python - 使用 Google Cloud Functions 在两个 BigQuery 项目之间传输数据

java - 如何解决 Jenkins 中 Spring Boot 项目自定义创建的依赖关系?