gcloudcomputessh 返回权限被拒绝(公钥)

2023-12-31

根据谷歌云文档 https://cloud.google.com/compute/docs/instances/connecting-to-instance#gcetools,如果我是具有“计算实例管理员”角色的项目成员,我应该能够使用 gcloud 工具连接到项目中的任何实例。

在 Google Cloud 控制台的项目 IAM 页面上,我已明确添加具有“计算实例管理员 (v1)”角色的用户名,但我仍然无法连接到由我们的某些自动化功能创建的实例。

[username]:~/src/infrastructure$ gcloud compute ssh [instance id]
Unauthorized use is strictly prohibited. All access and activity
is subject to logging and monitoring.
Permission denied (publickey).
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

我似乎能够连接到的唯一实例是我创建的实例。

这里可能出了什么问题?

作为旁注,根据本文档 https://cloud.google.com/compute/docs/instances/connecting-to-instance#thirdpartytools,我应该能够手动将 RSA 公钥添加到实例,然后使用 SSH 连接。

我添加了我的公钥~/.ssh/google_compute_engine.pub到实例元数据,然后尝试使用 SSH,但没有成功。

[username]:~/src/infrastructure$ ssh -i ~/.ssh/google_compute_engine [public ip of instance]
Unauthorized use is strictly prohibited. All access and activity is subject to logging and monitoring.
Received disconnect from 35.197.127.143 port 22:2: Too many authentication failures for matts
Connection to 35.197.127.143 closed by remote host.
Connection to 35.197.127.143 closed.

正如 Google 建议的那样,我不想手动管理实例访问的 SSH 密钥。我想gcloud compute ssh工作,所以我对第二次失败的关注不如对第一次失败的关注(除非它们相关)。


我试图从 docker 容器通过 ssh 连接到 gcloud 上的虚拟机。运行 Docker 容器时的默认用户名为root.

除非另有说明,否则gcloud compute ssh命令用途本地用户名就像 ssh 一样。现在,密钥传播似乎并不像这个名字root。唯一的指示来自机器的串行端口输出:

[    5.621630] google_metadata_script_runner[638]: 2020/10/21 09:43:01 logging client: rpc error: code = PermissionDenied desc = The caller does not have permission
[    5.622286] google_guest_agent[635]: 2020/10/21 09:43:01 logging client: rpc error: code = PermissionDenied desc = The caller does not have permission
Oct 21 09:43:01 private-cluster-bastion-dced90d6 google_metadata_script_runner[638]: 2020/10/21 09:43:01 logging client: rpc error: code = PermissionDenied desc = The caller does not have permission
Oct 21 09:43:01 private-cluster-bastion-dced90d6 google_guest_agent[635]: 2020/10/21 09:43:01 logging client: rpc error: code = PermissionDenied desc = The caller does not have permission

我可以通过添加一个来让它工作USER@机器名称的前缀,如中提到的https://cloud.google.com/sdk/gcloud/reference/compute/ssh#USER https://cloud.google.com/sdk/gcloud/reference/compute/ssh#USER

几乎任何用户名都可以。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gcloudcomputessh 返回权限被拒绝(公钥) 的相关文章

随机推荐