如何修复 gsutil 401 Anonymous caller does not have storage.objects.list access to the Google Cloud Storage bucket
问题:
运行类似以下命令时
gsutil_rsync_error.txt
gsutil rsync my-folder gs://my-bucket你看到类似这样的错误消息
gsutil_401_error.txt
Building synchronization state...
Caught non-retryable exception while listing gs://mfwh-backups/: ServiceException: 401 Anonymous caller does not have storage.objects.list access to the Google Cloud Storage bucket.
CommandException: Caught non-retryable exception - aborting rsync解决方案
此错误基本上是在告诉你你未登录!
首先,在 Google cloud 上为项目创建服务账户:服务账户页面直接链接。你需要根据你的设置确定要分配给服务账户的角色。如果你不知道该选择什么,只需分配存储的管理员权限,但请注意这可能会有安全影响,因为此账户也可能删除或创建存储桶等。
然后打开该服务账户的页面并创建新密钥!
这将给你一个 JSON 文件,如 my-project-4d267a915c4e.json。将它保存在你想运行 gsutil 的服务器或计算机上。我建议将其保存在 ~(用户主文件夹)中,使用原始文件名,例如 ~/my-project-4d267a915c4e.json。
然后你需要使用以下命令激活该服务账户
gcloud_activate_service_account.sh
gcloud auth activate-service-account --key-file [path to JSON file]例如
gcloud_activate_example.txt
gcloud auth activate-service-account --key-file [path to JSON file]Check out similar posts by category:
Cloud
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow