0
0
GCPcloud~5 mins

Cloud Shell and gcloud CLI in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need a ready-to-use command line tool to manage your cloud resources without installing anything on your computer. Cloud Shell is a browser-based terminal with gcloud CLI pre-installed, letting you control Google Cloud easily from anywhere.
When you want to quickly try Google Cloud commands without setup on your computer
When you need to manage cloud resources from a device that does not have gcloud installed
When you want a consistent environment with all Google Cloud tools ready to use
When you want to run scripts or commands securely without exposing your local machine
When you want to learn Google Cloud commands interactively with instant access
Commands
This command opens a browser window to log in to your Google account and authorize gcloud CLI to manage your cloud resources.
Terminal
gcloud auth login
Expected OutputExpected
Your browser has been opened to visit: https://accounts.google.com/o/oauth2/auth?... You are now logged in as [user@example.com]. To set the active project, run: $ gcloud config set project PROJECT_ID
This sets the default project for your gcloud commands so you don't have to specify it every time.
Terminal
gcloud config set project example-project-123
Expected OutputExpected
Updated property [core/project].
This lists all the virtual machine instances in your current project, showing their status and zone.
Terminal
gcloud compute instances list
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-vm us-central1-a e2-medium 10.128.0.2 34.68.123.45 RUNNING
Shows help information about gcloud commands and usage, useful when you want to learn what commands are available.
Terminal
gcloud help
Expected OutputExpected
gcloud is a tool to manage resources and applications hosted on Google Cloud. Usage: gcloud [optional flags] <GROUP | COMMAND> [args] Available groups: auth Manage authentication credentials for the gcloud tool compute Manage Google Compute Engine resources config View and edit Cloud SDK properties help Display detailed help Run 'gcloud help COMMAND' for detailed information on a command.
Key Concept

If you remember nothing else, remember: Cloud Shell gives you instant access to gcloud CLI in a browser, so you can manage Google Cloud without setup.

Common Mistakes
Trying to run gcloud commands without logging in first
gcloud commands require authentication to access your cloud resources, so they will fail if you are not logged in.
Always run 'gcloud auth login' first to authenticate before running other commands.
Not setting the active project before running commands
Without setting the project, gcloud commands may fail or act on the wrong project.
Use 'gcloud config set project PROJECT_ID' to set your working project.
Summary
Use Cloud Shell to get a ready-to-use terminal with gcloud CLI in your browser.
Run 'gcloud auth login' to authenticate your session.
Set your active project with 'gcloud config set project' to target commands correctly.
Use 'gcloud compute instances list' to see your virtual machines.
Use 'gcloud help' to explore available commands and options.