Essential Google Cloud Shell Commands: A Quick Reference

This guide offers a curated collection of practical Google Cloud Shell commands that streamline your cloud management tasks. These commands cover various areas, from project management to networking.

How to prevent project deletion in Google Cloud Shell

This is a great command to protect your cloud projects from overzealous system administrators. This is ideal for a production environment.

gcloud beta resource-manager org-policies enable-enforce \     --organization $ORG_ID compute.restrictXpnProjectLienRemoval

Explanation:

  • This command enforces an organization-level policy that prevents the removal of a project lien, which acts as a safeguard against accidental deletion.
  • Replace $ORG_ID with your organization’s ID.

How to enable service APIs in Google Cloud Shell

Service APIs are disabled by default. Therefore, the first time your log into Google Cloud, the majority of APIs will need to be enabled and associated to your project:

gcloud services enable container.googleapis.com
gcloud services enable containerregistry.googleapis.com
gcloud services enable cloudbuild.googleapis.com
gcloud services enable iam.googleapis.com
gcloud services enable logging.googleapis.com
gcloud services enable monitoring.googleapis.com
gcloud services enable storage-api.googleapis.com
gcloud services enable storage-component.googleapis.com
gcloud services enable sourcerepo.googleapis.com

How to check the configuration of your project in Google Cloud Shell

# Check default project setting

# Check default project
gcloud config get-value project

# Set default project (change myproject value)

# Set default project (replace 'myproject' with your project ID)
gcloud config set project myproject

How to create a networking firewall rule to open a port in Google Cloud Shell

One of the many tasks you will need to do as a Cloud Administrator is to open firewall port. The Cloud Shell makes this process dead easy, here is how to create a firewall rule to open up the 8000 port range

gcloud compute firewall-rules create open-range-8000 \
  --action allow \
  --direction ingress \
  --rules tcp:8000-9000 \
  --source-ranges 0.0.0.0/0 \
  --priority 1000 \
  --target-tags open-range-8000

How to list available production compute resources for Deployment Manager in Google Cloud Shell

 gcloud deployment-manager types list | grep v1.*instance 

Example:

gcloud deployment-manager types list | grep v1.*instance spanner.v1.instance compute.v1.instanceGroupManager sqladmin.v1beta4.instance compute.v1.instanceGroup compute.v1.instanceTemplatecompute.v1.instance

Google Cloud Shell Commands: Your Questions Answered


Q: What is Google Cloud Shell?

A: Google Cloud Shell is a browser-based command-line environment that gives you access to your Google Cloud Platform (GCP) resources. It comes pre-loaded with essential tools like the gcloud command-line interface, making it a convenient way to manage your cloud infrastructure from anywhere.

Q: Why should I use Google Cloud Shell?

A: Cloud Shell offers several advantages:

  • No local installation: You don’t need to install the Google Cloud SDK or other tools on your computer.
  • Accessibility: Access your projects from any browser, on any device.
  • Pre-installed tools: Cloud Shell comes equipped with the gcloud CLI and other useful utilities.
  • Persistent storage: Your home directory persists between sessions, so your files are always available.

Q: How do I access Google Cloud Shell?

A: You can access Cloud Shell directly from the Google Cloud Console by clicking the “Activate Cloud Shell” button in the top right corner.

Q: Are there any costs associated with using Google Cloud Shell?


A: Cloud Shell is free to use, but any resources you create or use through it may incur charges (e.g., compute instances, storage).

Q: How can I find more Google Cloud Shell commands?

A: The official Google Cloud documentation provides a comprehensive list of gcloud commands and other Cloud Shell resources:

Cloud Shell Documentation

gcloud CLI Reference

Q: Can I customize my Google Cloud Shell environment?

A: Yes! You can customize your shell environment by editing configuration files like .bashrc, installing additional tools, and setting up aliases to make your workflow more efficient.

Elsewhere On TurboGeek:  Unveiling the Power of Kali Linux

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป