Google Associate Cloud EngineerSetting up a cloud solution environmentMedium

A new Cloud Engineer is setting up their local development environment and has installed the Google Cloud SDK. They attempt to run a `gcloud` command, but it fails with an authentication error. They realize they haven't authenticated their `gcloud` CLI. Which command should they use to authenticate their local `gcloud` environment with their Google Cloud account?

  1. A`gcloud auth login`
  2. B`gcloud config set account`
  3. C`gcloud init`
  4. D`gcloud auth activate-service-account`
Show answer & explanation

Correct answer: A. `gcloud auth login`

The `gcloud auth login` command initiates the authentication flow, typically opening a web browser to allow the user to sign in with their Google account, thereby authenticating the `gcloud` CLI to perform actions on their behalf.

Why the other options are wrong

  • B. `gcloud config set account` changes the active account in the current configuration but doesn't perform the initial authentication.
  • C. `gcloud init` is used for initialization, which includes authentication, but `gcloud auth login` is the direct command for just authentication.
  • D. This command is used to activate a service account, not a user account, for authentication.

gcloud auth login

The `gcloud auth login` command authenticates the Google Cloud CLI with a user's Google account, granting it access to Google Cloud resources.

  • Initiates a browser-based authentication flow.
  • Stores user credentials locally.
  • Required for most `gcloud` operations as a user.

Memory trick: To log in to gcloud, you need to 'auth login'.

More Setting up a cloud solution environment questions