متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 22Google Cloud CLI · Cloud

Install and set up the Google Cloud CLI

The Google Cloud CLI (gcloud, with gsutil and bq) manages Google Cloud from the terminal: projects, VMs, GKE clusters, Cloud Storage, IAM, logs and more. This guide installs it from Google's repository on RHEL and Ubuntu, sets up login, the default project and region, named configurations for many projects, and the safe way to work with service accounts — plus the fixes for the most common errors.

  • 9 الدروس
  • 8 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

22.1

Know it before you install

Everything in Google Cloud lives in a project. gcloud keeps the active account, project and region in a configuration. Programs that use Google's libraries (Terraform, Python SDK) use a separate login: Application Default Credentials (ADC).

ItemValue
Packagegoogle-cloud-cli (+ extra components like google-cloud-cli-gke-gcloud-auth-plugin)
Programsgcloud, gsutil (old storage tool), bq (BigQuery)
Config~/.config/gcloud/ (configurations, tokens, ADC file)
EnvironmentCLOUDSDK_CORE_PROJECT, CLOUDSDK_ACTIVE_CONFIG_NAME, GOOGLE_APPLICATION_CREDENTIALS
NetworkHTTPS (443) to *.googleapis.com and accounts.google.com

الأوامر في هذا الدرس

22.2

Install on RHEL, Rocky, Alma and Fedora

Add the repository (use el9 or el10 for your version), then install:

cat > /etc/yum.repos.d/google-cloud-sdk.repo <<'EOF'
[google-cloud-cli]
name=Google Cloud CLI
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el9-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
dnf -y install google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin
gcloud version

22.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y apt-transport-https ca-certificates gnupg curl
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" > /etc/apt/sources.list.d/google-cloud-sdk.list
apt-get update
apt-get install -y google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin

ملاحظة

With the package install, add components with dnf/apt (for example google-cloud-cli-gke-gcloud-auth-plugin), not with gcloud components install.

22.4

First configuration: login, project and region

gcloud init asks for everything step by step. On a server without a browser, add --no-browser (or --no-launch-browser):

gcloud init
gcloud auth login --no-browser
gcloud config set project shop-prod-123456
gcloud config set compute/region europe-west3
gcloud config set compute/zone europe-west3-a
gcloud config list

Many projects? Make one named configuration per project or environment and switch between them:

gcloud config configurations create dev
gcloud config set project shop-dev-654321
gcloud config configurations list
gcloud config configurations activate prod

Login for tools like Terraform and SDKs (ADC):

gcloud auth application-default login
gcloud auth application-default set-quota-project shop-prod-123456
SettingWhy
core/projectEvery command goes to this project. A wrong one = changes in the wrong place.
compute/region, compute/zoneNo --region / --zone on every command.
Named configurationsSafe switching between dev and prod.
ADC loginTerraform and SDKs use your identity without key files.

في العمل

Do not download service account keys. To act as a service account, use impersonation: gcloud config set auth/impersonate_service_account deployer@shop-prod-123456.iam.gserviceaccount.com. In CI use Workload Identity Federation (GitHub Actions, GitLab) — no keys at all.

الأوامر في هذا الدرس

22.5

Daily use: the commands and the real uses

gcloud projects list
gcloud services enable compute.googleapis.com container.googleapis.com
gcloud compute instances list --format="table(name,zone.basename(),status,networkInterfaces[0].networkIP)"
gcloud compute ssh vm1 --tunnel-through-iap
gcloud storage ls gs://shop-backups/
gcloud storage cp backup.tar.gz gs://shop-backups/web1/
gcloud container clusters get-credentials prod --region europe-west3
gcloud logging read 'severity>=ERROR' --limit 20 --freshness 1h
gcloud iam service-accounts list
gcloud projects get-iam-policy shop-prod-123456 --format=json

--format (table, json, yaml, value) and --filter make output easy for people and scripts: gcloud compute instances list --filter="status=RUNNING" --format="value(name)".

Real uses at work:

  • Build and check resources; reports with --format and --filter.
  • SSH to VMs through IAP — no public IPs and no open port 22.
  • Get the kubeconfig of GKE; copy backups to Cloud Storage.

الأوامر في هذا الدرس

22.6

Make it safe

Security checklist:

  • 2-step verification on all Google accounts; least-privilege IAM roles (not Owner/Editor for daily work).
  • No service account key files; impersonation for people, Workload Identity Federation for CI, attached service accounts for VMs.
  • Check the project before every change: gcloud config list.
  • ~/.config/gcloud/ holds your tokens: never copy it to shared machines; gcloud auth revoke on shared hosts.
  • Use IAP or private access instead of public IPs and open SSH.
  • Keep the CLI updated with dnf/apt.

الأوامر في هذا الدرس

22.7

Update and remove

dnf -y upgrade google-cloud-cli
apt-get install --only-upgrade -y google-cloud-cli
dnf -y remove google-cloud-cli
apt-get purge -y google-cloud-cli
rm -rf ~/.config/gcloud

الأوامر في هذا الدرس

22.8

Fix common problems

ProblemCauseFix
You do not currently have an active account selectedNo login.gcloud auth login, then gcloud config set account ….
The required property [project] is not currently setNo default project.gcloud config set project ID.
API [compute.googleapis.com] not enabled on projectThe service is off for this project.gcloud services enable compute.googleapis.com.
PERMISSION_DENIED: … does not have … permissionYour role is too small.Check with gcloud projects get-iam-policy; ask for a role.
gke-gcloud-auth-plugin … not found with kubectlThe GKE auth plugin is missing.Install google-cloud-cli-gke-gcloud-auth-plugin, get credentials again.
Terraform: could not find default credentialsNo ADC login.gcloud auth application-default login.
ERROR: (gcloud.components.install) You cannot perform this action because the Google Cloud CLI component manager is disabledPackage install.Install the component with dnf/apt.

الأوامر في هذا الدرس

22.9

Next steps

1How do you act as a service account without a key file?

With impersonation: --impersonate-service-account or the auth/impersonate_service_account setting.

2Terraform says it can not find credentials, but gcloud works. Why?

Terraform uses Application Default Credentials. Run gcloud auth application-default login.

كل الأوامر في هذا الفصل