简体   繁体   English

从CD管道通过SSH进入Compute Engine VM

[英]SSH into Compute Engine VM from CD Pipeline

I'm having a bear of a time getting my Google service account to ssh into our Compute Engine instance from bitbucket pipelines. 我花了点时间让我的Google服务帐户从bitbucket管道进入我们的Compute Engine实例。

Script:
gcloud compute ssh instance1 --zone us-central1-a --quiet --verbosity=info --command="gracefully shutdown processes" && \
gcloud compute scp ~/ instance1:~/ --zone us-central1-a --quiet --recurse --compress && \
gcloud compute ssh instance1 --zone us-central1-a --quiet --verbosity=info --command="start the services"

ERROR: (gcloud.compute.ssh) Could not SSH into the instance.  It is possible that your SSH key has not propagated to the instance yet. Try running this command again.  If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic.
Permission denied (publickey).
lost connection
ERROR: (gcloud.compute.scp) [/usr/bin/scp] exited with return code [1].

I've even tried the old fashioned way of SSHing in without gcloud. 我什至尝试了不带gcloud的SSH老式方式。 I added the public key to the instance using metadata . 我使用metadata将公钥添加到实例。 I can SSH in on my local machine, but with bitbucket pipelines, I get a permission denied error. 我可以在本地计算机上使用SSH进行登录,但是使用Bitbucket管道,会出现权限被拒绝的错误。

script:
        - echo $PRIVATE_SSH_KEY > ./ssh_key
        - chmod 400 ssh_key
        - ssh -t -t -i ssh_key bitbucket-service-account@<IP>

Permission denied (publickey).

What could I possibly be doing wrong? 我可能做错了什么?

The role https://www.googleapis.com/auth/compute is needed. 需要https://www.googleapis.com/auth/compute角色。 Add that role to your VM's service account[1]. 将该角色添加到您的VM的服务帐户[1]。 Unfortunately is not documented yet on Google Cloud documentation. 很遗憾,尚未在Google Cloud文档中进行记录。

[1] https://cloud.google.com/iam/docs/granting-roles-to-service-accounts [1] https://cloud.google.com/iam/docs/granting-roles-to-service-accounts

Thanks for helping Alessio. 感谢您对Alessio的帮助。 I was able to figure it out after digging around. 经过挖掘,我能够弄清楚。

  1. Create bitbucket key pair by using the bitbucket ssh keygen tool 使用bitbucket ssh keygen工具创建bitbucket密钥对
  2. Copy the public key from step 1 to the Compute Engine Instance but remember to paste your bitbucket username at the end of the key 将第1步中的公钥复制到Compute Engine实例,但请记住将您的bitbucket用户名粘贴到密钥末尾
  3. ssh -i ~/.ssh/config <Bitbucket-Username>@<IP-OF-VM>

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

相关问题 SSH 密钥不断从 Google Compute Engine VM 中删除 - SSH keys keep getting deleted from Google Compute Engine VM SSH 作为 GitHub 操作机器人进入 Google Compute Engine VM - SSH into Google Compute Engine VM as a GitHub Actions bot 无法通过SSH登录到GCP Compute Engine VM实例 - Not able to login via SSH to GCP Compute Engine VM instance Google Compute Engine-如果禁用ssh端口,则备用登录到VM实例 - Google Compute Engine - alternative log in to VM instance if ssh port is disabled gcloud 将 ssh 从一个虚拟机计算到 Google Cloud 上的另一个虚拟机 - gcloud compute ssh from one VM to another VM on Google Cloud 来自ubuntu的ssh谷歌计算引擎实例 - ssh google compute engine instance from ubuntu 无法通过 ssh 连接到 Google Cloud Dataproc 的主节点,但可以通过 ssh 连接到 Compute Engine VM - Unable to ssh to master node of Google Cloud Dataproc, but can ssh to Compute Engine VM 尝试从github克隆到Google云计算引擎上的VM - Trying to clone from github to VM on google cloud compute engine Google-Compute-Engine 虚拟机实例:添加磁盘后无法登录/SSH 虚拟机实例 - Google-Compute-Engine Virtual Machine Instance: Unable to login/SSH the VM instance after adding a disk 如何使用 Python 而不是 CLI SSH 到 Google Compute Engine VM 实例? - How do you SSH into a Google Compute Engine VM instance with Python rather than the CLI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM