> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# General Instructions Linux Machine

> Prepare an isolated Ubuntu VM to run Google Cloud commands and centralize workflows with full control over CLI configuration.

Prepare an isolated Ubuntu VM to run Google Cloud commands without relying on Cloud Shell. This approach centralizes your workflows on a dedicated environment and gives you full control over the CLI configuration.

## Table of Contents

1. [Launch the Ubuntu VM](#launch-the-ubuntu-vm)
2. [Install Prerequisites](#install-prerequisites)
3. [Add the Google Cloud SDK Repository](#add-the-google-cloud-sdk-repository)
4. [Install the Google Cloud CLI](#install-the-google-cloud-cli)
5. [Authenticate and Configure `gcloud`](#authenticate-and-configure-gcloud)
6. [Optional Configuration](#optional-configuration)
7. [References](#references)

***

## Launch the Ubuntu VM

1. In your Playgrounds console, choose **Ubuntu**.
2. Click **Launch Now**.
3. Wait until the VM status shows **Ready**.

<Callout icon="lightbulb" color="#1CB2FE">
  Assign a static external IP if you need consistent SSH access over time.
</Callout>

***

## Install Prerequisites

SSH into your new VM and install the required packages:

```bash theme={null}
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
```

| Package             | Purpose                                            |
| ------------------- | -------------------------------------------------- |
| apt-transport-https | Enables APT to use repositories accessed via HTTPS |
| ca-certificates     | Provides SSL certificates                          |
| gnupg               | Manages GPG keys                                   |
| curl                | Downloads files from the command line              |

***

## Add the Google Cloud SDK Repository

1. **Import Google’s public key** for APT:

   ```bash theme={null}
   curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \
     | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
   ```

2. **Add the Cloud SDK repo** to your sources list:

   ```bash theme={null}
   echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] \
   https://packages.cloud.google.com/apt cloud-sdk main" \
     | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
   ```

***

## Install the Google Cloud CLI

Update the package index and install the SDK:

```bash theme={null}
sudo apt-get update
sudo apt-get install -y google-cloud-cli
```

Wait for the installation to finish; you’ll now have access to `gcloud`, `gsutil`, and other SDK components.

***

## Authenticate and Configure `gcloud`

Run the initialization wizard:

```bash theme={null}
gcloud init
```

Follow these steps:

1. Select or create a configuration (press **Enter** for `[default]`).
2. Choose an account:
   ```text theme={null}
   [1] existing-service-account@your-project.iam.gserviceaccount.com
   [2] Log in with a new account
   Enter your choice: 2
   ```
3. Approve usage of a personal account (`Y`).
4. **Authorize**:
   * Copy the URL shown in your terminal.
   * Open it in an incognito/private browser window.
   * Sign in with your Google credentials.
   * Grant permissions and copy the authorization code.
5. **Paste** the code back into the terminal.
6. Select your project ID:
   ```text theme={null}
   Pick cloud project to use:
   [1] your-project-id
   ```
7. (Optional) Set default region/zone now or skip.

<Callout icon="triangle-alert" color="#FF6B6B">
  Do not share your authorization code. Anyone with this code can access your Google Cloud resources.
</Callout>

***

## Optional Configuration

Use these commands to set your default compute region and zone:

| Setting                | Command                                        |
| ---------------------- | ---------------------------------------------- |
| Default Compute Region | `gcloud config set compute/region YOUR_REGION` |
| Default Compute Zone   | `gcloud config set compute/zone YOUR_ZONE`     |

You can always update these later with `gcloud config set`.

***

## References

* [Google Cloud SDK Documentation](https://cloud.google.com/sdk/docs/install)
* [gcloud CLI Overview](https://cloud.google.com/sdk/gcloud/)
* [Google Cloud Regions & Zones](https://cloud.google.com/about/locations)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/gke-google-kubernetes-engine/module/f7a534a3-6dcf-42b8-96c8-648e59b02830/lesson/f4a95bd8-89d5-4de2-bbcb-425d76068cf7" />
</CardGroup>
