How to Login Google cloud witch CLI

Feb 11, 2025 min read

gcloud

How to Login to Google Cloud Using the Command Line (CLI)

Hey everyone! Welcome back to my blog at yuswitayudi.github.io. Today, I’m going to walk through how to log in to Google Cloud using the command line. If you’re managing cloud resources, using the CLI can save a lot of time and make things more efficient.

Prerequisites

Before starting, make sure you have:

  • A Google Cloud account
  • Google Cloud SDK installed on your system
you just need run this if you are  linux based sudo snap install google-cloud-cli --classic

If Google Cloud SDK isn’t installed yet, follow this guide to set it up.

Step 1: Open the Terminal

The first step is to open a terminal or command prompt. This is where the authentication commands will be executed.

Step 2: Run the Login Command

To authenticate, run the following command:

gcloud auth login

This will open a web browser prompting for Google account sign-in. Please select the gmail account that have access to Google cloud. After granting permissions, a success message should appear in the terminal.

Step 3: Set the Default Project

After logging in, set the default project with:

gcloud config set project [PROJECT_ID]

Replace [PROJECT_ID] with the actual project ID, which can be found in the Google Cloud Console.

Step 4: Verify Authentication

To confirm everything is set up correctly, run:

gcloud auth list

This will display the active authenticated account. If the expected email appears, the setup is complete.

Conclusion

That’s it! Now logging into Google Cloud using the CLI is straightforward. Whether managing projects manually or automating tasks, the command line provides an efficient way to interact with Google Cloud.