> For the complete documentation index, see [llms.txt](https://www.techwithtyler.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.techwithtyler.dev/cloud-security/gcp/gcp-cli-cheat-sheet.md).

# GCP CLI Cheat Sheet

{% embed url="<https://docs.cloud.google.com/sdk/gcloud/reference>" %}

## Authentication

### Login

{% tabs %}
{% tab title="Interactive Login" %}
{% code overflow="wrap" %}

```shellscript
gcloud auth login ## complete auth in web browser
```

{% endcode %}
{% endtab %}

{% tab title="Service Account" %}
{% code overflow="wrap" %}

```shellscript
gcloud auth activate-service-account --key-file=<SERVICE_ACCOUNT_KEY>.json
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Configuring Multiple Profiles

* Similar to aws `--profile` gcloud allows you to configure multiple profiles when you need to authenticate as different identities&#x20;

#### Profile Setup

{% code overflow="wrap" %}

```shellscript
gcloud config configurations create <PROFILE_NAME>
gcloud auth activate-service-account --key-file=<SERVICE_ACCOUNT_KEY>.json
gcloud config set project <PROJECT_NAME>
```

{% endcode %}

#### Switch Between Profiles

{% code overflow="wrap" %}

```shellscript
gcloud compute instances list --configuration=dev
gcloud compute instances list --configuration=prod
```

{% endcode %}

#### Set Default Profile

{% code overflow="wrap" %}

```shellscript
gcloud config configurations activate <PROFILE>
```

{% endcode %}

### Configuration File

* The configurations live in `~/.config/gcloud/configurations`
