Cloud
gcloud CLI — auth, projects, and everyday operations
Authenticate the gcloud CLI, confirm which account and project you are in, switch context safely, and run the everyday list, describe, log-tail, and deploy commands.
Quick reference — reach for these first
gcloud config listPrint the active account, project and region before you touch anything — this is the first command of every session.gcloud auth loginAuthorize gcloud with your Google account in a browser. Add gcloud auth application-default login so client libraries get ADC too.gcloud config set project PROJECT_IDPoint every later command at PROJECT_ID. Confirm with gcloud projects describe PROJECT_ID.gcloud compute instances listEnumerate VMs across zones. Swap the group (run, container, storage, sql) to inventory other services the same way.gcloud logging read '...' --limit 20 --freshness 1hRead recent entries for a resource type. One central read path covers Cloud Run, GKE and Compute Engine.How gcloud resolves identity, project and region for every command
Text equivalent: Credentials come from two commands: gcloud auth login creates user credentials used by the gcloud CLI, and gcloud auth application-default login creates Application Default Credentials used by client libraries. The active gcloud configuration holds the account, project and default region, which gcloud config list prints. Every gcloud command reads the active configuration to decide which account acts on which project in which region. Switch context by activating another named configuration or passing per-command flags such as --project and --region. GCP has no subscription; the billing link is the billing account.
Common tasks
Task · Command · What to check
| Task | Command | What to check |
|---|---|---|
| Authenticate the CLI (interactive) | gcloud auth login | Browser completes; gcloud auth list shows your account marked with a '*'. |
| Set up ADC for local application code | gcloud auth application-default login | Writes ~/.config/gcloud/application_default_credentials.json; client libraries now authenticate without a key file. |
| Confirm the active context (do this first) | gcloud config list | [core] account and [core] project are the exact identity and project you intend to act on. |
| Switch the active project | gcloud config set project PROJECT_ID | gcloud config get-value project echoes PROJECT_ID. |
| Switch the active account | gcloud config set account ACCOUNT | gcloud auth list marks ACCOUNT active; re-run gcloud auth login if it shows no credentials. |
| Set a default region / zone | gcloud config set compute/region REGION | gcloud config get-value compute/region returns REGION, so region-scoped commands stop prompting. |
| Keep one named config per environment | gcloud config configurations activate CONFIG | gcloud config configurations list shows IS_ACTIVE=True on CONFIG and its bound account+project. |
| List the projects you can see | gcloud projects list | PROJECT_ID appears with its project number and display name. |
| Confirm the billing link (GCP's 'subscription') | gcloud billing projects describe PROJECT_ID | billingEnabled: true and billingAccountName matches the expected BILLING_ACCOUNT_ID. |
| Describe one resource in detail | gcloud compute instances describe NAME --zone ZONE | Returns status, machineType and network IPs for NAME; confirms you are reading the right object. |
| Read recent logs for a resource | gcloud logging read 'resource.type="cloud_run_revision"' --limit 20 --freshness 1h | Entries stream back newest-first; empty output means wrong filter, wrong project, or no recent traffic. |
| Get kubeconfig for a GKE cluster | gcloud container clusters get-credentials CLUSTER --region REGION | kubeconfig updated; kubectl config current-context names gke_PROJECT_ID_REGION_CLUSTER. |
| Enable a required API (LABEL: changes project config) | gcloud services enable run.googleapis.com | gcloud services list --enabled lists run.googleapis.com; retry the command that failed with SERVICE_DISABLED. |
| Deploy a Cloud Run service (LABEL: BILLABLE, creates resources) | gcloud run deploy SERVICE --image IMAGE --region REGION | Command prints a Service URL; gcloud run services list shows SERVICE with a Ready condition. |
From zero: authenticate, confirm context, do a safe read, then one scoped change
docs-checked
gcloud auth login
# Opens a browser; on return:
# You are now logged in as [you@example.com].gcloud config set project PROJECT_ID && gcloud config set compute/region REGION
# Updated property [core/project].
# Updated property [compute/region].gcloud config list
# [compute]
# region = REGION
# [core]
# account = you@example.com
# project = PROJECT_IDgcloud billing projects describe PROJECT_ID
# billingAccountName: billingAccounts/BILLING_ACCOUNT_ID
# billingEnabled: truegcloud compute instances list
# NAME ZONE STATUS
# web-1 REGION-a RUNNINGgcloud services enable run.googleapis.com
# Operation finished successfully.gcloud services list --enabled --filter='config.name:run.googleapis.com'
# NAME TITLE
# run.googleapis.com Cloud Run Admin APITroubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| PERMISSION_DENIED / 403 on a command | gcloud config list | Whether the active account and project are the ones that actually hold the needed role (most 403s are wrong-context, not missing-role). | gcloud projects get-iam-policy PROJECT_ID — confirm the account has the role; grant with gcloud projects add-iam-policy-binding. |
| Reauthentication required / invalid_grant / credentials have expired | gcloud auth list | Whether the account still has a live token or was revoked, expired, or never credentialed. | Re-run gcloud auth login; for client-library errors also run gcloud auth application-default login. |
| Change landed on the wrong project or account | gcloud config configurations list | Which named configuration (and therefore which account+project) was active when the command ran. | gcloud config configurations activate CONFIG, or set project/account explicitly, then re-run with --project to be certain. |
| Required argument --region / --zone not specified | gcloud config get-value compute/region | Whether any default region or zone is configured for region-scoped commands. | gcloud config set compute/region REGION (and run/region for Cloud Run), or pass --region / --zone per command. |
| Quota exceeded / RESOURCE_EXHAUSTED / HTTP 429 | Re-run the command with --log-http and read the 429 response body | Which limit is being hit — a per-minute API rate limit versus a hard resource quota. | Back off and retry for rate limits; for resource quotas open IAM & Admin > Quotas and request an increase. |
| API [x] has not been used / SERVICE_DISABLED | gcloud services list --enabled | Whether the required API is enabled on this project at all. | gcloud services enable SERVICE.googleapis.com, then retry the original command. |
| The billing account for project is not found / FAILED_PRECONDITION on create | gcloud billing projects describe PROJECT_ID | Whether a billing account is linked and enabled for the project. | Link one: gcloud billing projects link PROJECT_ID --billing-account BILLING_ACCOUNT_ID (needs Billing Account User). |
References
- gcloud CLI overviewcloud.google.com
- Authorize the gcloud CLIcloud.google.com
- Manage gcloud configurationscloud.google.com
- gcloud auth command referencecloud.google.com
- gcloud logging read referencecloud.google.com
Google Cloud CLI (gcloud) 500+ on macOS or Linux; commands target a single GCP project you hold IAM access to. GCP has no "subscription" — the closest link is the billing account.