هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
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).
| Item | Value |
|---|---|
| Package | google-cloud-cli (+ extra components like google-cloud-cli-gke-gcloud-auth-plugin) |
| Programs | gcloud, gsutil (old storage tool), bq (BigQuery) |
| Config | ~/.config/gcloud/ (configurations, tokens, ADC file) |
| Environment | CLOUDSDK_CORE_PROJECT, CLOUDSDK_ACTIVE_CONFIG_NAME, GOOGLE_APPLICATION_CREDENTIALS |
| Network | HTTPS (443) to *.googleapis.com and accounts.google.com |
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 versionInstall 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.
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 listMany 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 prodLogin for tools like Terraform and SDKs (ADC):
gcloud auth application-default login
gcloud auth application-default set-quota-project shop-prod-123456| Setting | Why |
|---|---|
core/project | Every command goes to this project. A wrong one = changes in the wrong place. |
compute/region, compute/zone | No --region / --zone on every command. |
| Named configurations | Safe switching between dev and prod. |
| ADC login | Terraform 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.
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
--formatand--filter. - SSH to VMs through IAP — no public IPs and no open port 22.
- Get the kubeconfig of GKE; copy backups to Cloud Storage.
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 revokeon shared hosts.- Use IAP or private access instead of public IPs and open SSH.
- Keep the CLI updated with
dnf/apt.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
You do not currently have an active account selected | No login. | gcloud auth login, then gcloud config set account …. |
The required property [project] is not currently set | No default project. | gcloud config set project ID. |
API [compute.googleapis.com] not enabled on project | The service is off for this project. | gcloud services enable compute.googleapis.com. |
PERMISSION_DENIED: … does not have … permission | Your role is too small. | Check with gcloud projects get-iam-policy; ask for a role. |
gke-gcloud-auth-plugin … not found with kubectl | The GKE auth plugin is missing. | Install google-cloud-cli-gke-gcloud-auth-plugin, get credentials again. |
Terraform: could not find default credentials | No ADC login. | gcloud auth application-default login. |
ERROR: (gcloud.components.install) You cannot perform this action because the Google Cloud CLI component manager is disabled | Package install. | Install the component with dnf/apt. |
Next steps
- Quick how-to: Get the GKE kubeconfig.
- Command pages: gcloud, kubectl.
- gcloud at work: gcloud in DevOps.
- Build Google Cloud with code: Install and set up Terraform. The other clouds: AWS CLI, Azure CLI.
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.