我确信这会很简单,但找不到任何文档或解决方案。
我正在尝试使用 gcloud 编写一个脚本来在我的 GCP 实例中执行一些操作。
是否可以仅通过命令行使用 gcloud 登录/身份验证?
Thanks
这里有几个选择(取决于您到底想做什么)。
第一个选项是使用登录--no-launch-browser
选项。这仍然需要人类用户的交互,但不需要您正在使用的计算机上有浏览器:
> gcloud auth login --no-launch-browser
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_account&response_type=code&client_id=32555940559.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute&access_type=offline
Enter verification code: *********************************************
Saved Application Default Credentials.
You are now logged in as [[email protected] /cdn-cgi/l/email-protection].
Your current project is [None]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
非交互式选项涉及服务帐户 https://developers.google.com/identity/protocols/OAuth2ServiceAccount。链接的文档比我更好地解释了它们,但您需要做的简短版本如下:
在中创建一个服务帐户谷歌开发者控制台 https://console.developers.google.com。确保它具有适当的“范围”(这些权限决定了此服务帐户可以执行的操作。下载相应的 JSON 密钥文件。
Run gcloud auth activate-service-account --key-file <path to key file>
.
请注意,Google Compute Engine VM 附带的服务帐户略有不同;描述了差异here https://cloud.google.com/compute/docs/authentication#general.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)