[英]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.
经过挖掘,我能够弄清楚。
ssh -i ~/.ssh/config <Bitbucket-Username>@<IP-OF-VM>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.