gcloud init. The gcloud init command performs
the following steps:
Authenticates with user account credentials, and then authorizes the gcloud CLI to access Google Cloud resources on your behalf. You can also do this separately with the
gcloud auth logincommand.Sets up a gcloud CLI configuration and sets core properties such as the active account, the current project, and if applicable, the default Compute Engine region and zone.
If you've already initialized the gcloud CLI, running gcloud init
again lets you change existing settings or create a new configuration.
Initialize the gcloud CLI
To initialize the gcloud CLI:
-
Run
gcloud init:gcloud initIf you're using a remote terminal session, add the
--console-only flag. This flag provides the URL to the authentication and authorization flow instead of attempting to open it in your default browser.gcloud init --console-only
-
Create or select a configuration if prompted.
For new gcloud CLI installations,
gcloud initcreates a configuration nameddefaultfor you and sets it as the active configuration. If you have existing configurations,gcloud initprompts you to choose between the following options:- Re-initialize the active configuration.
- Switch to another configuration and re-initialize it.
- Create a new configuration.
-
Complete the authentication and authorization steps when prompted.
If you have previously authorized access to Google Cloud, you might be prompted to sign in again and grant access in a web browser, or to select an existing account.
If you used the
--console-onlyflag and sign-in is required, copy and paste the provided authorization URL into another browser window and follow the prompts. -
Choose a Google Cloud project if prompted.
If you only have access to one project—including the default project for your user account—
gcloud initselects it for you.Otherwise, you can select a project from a list of projects on which you have the Owner, Editor, or Viewer roles. If you have access to more than 200 projects, you're prompted to enter a project ID, create a new project, or list projects.
-
Choose a default Compute Engine zone if prompted. If you don't have the Compute Engine API enabled or you already have a default zone in your project-level metadata, this step is skipped.
View configuration properties
To view the properties set through the gcloud init command, use the
gcloud config list command. The command
returns an output similar to the following example:
[compute]
region = us-east1
zone = us-east1-b
[core]
account = dana@example.com
disable_usage_reporting = False
project = example-project
What's next
To learn more about authentication for the gcloud CLI, see Authentication for the gcloud CLI.
To learn more about authorizing Application Default Credentials (ADC) for Cloud Client Libraries and Google API Client Libraries, see Set up Application Default Credentials.
To learn more about managing configurations, see Manage gcloud CLI configurations.
To learn more about managing properties, see Manage gcloud CLI properties.