Skip to content

GCP: Tips

rsync to compute instance

cat ~/.config/gcloud-compute-ssh

exec gcloud compute ssh "$host" -- "[email protected]"

Remember to make the file executable.

chmod +x ~/.config/gcloud-compute-ssh

Now you can rsync to your compute as follows

rsync -e ~/.config/gcloud-compute-ssh -r ./mydir/ <compute-instance-id>:/path/to/sync/to

Run a command in remote GCE instance

gcloud compute ssh <instance-id> -- 'cp /path/to/source /path/to/dest '

Google Source Repository Git Access

Add your keys here

And in your ~/.gitconfig file, add following

[credential ""]
    helper =

Mchine Types


Duplicate images across projects

gcloud compute --project=<destination-project-id> images create <destination-image-name> --source-image=<source-image-name> --source-image-project=<source-project-id>

Access images across projects

Access image that belongs to project A from project B

  1. Get the address of Service Account from project B
  2. Go to Project B IAM & admin > IAM from menu
  3. Click Add button on top left.
  4. Paste the SA address as Member
  5. Select Compute Engine > Compute Image User
gcloud projects add-iam-policy-binding [PROJECT_ID] \
    --member serviceAccount:[SERVICE_ACCOUNT_EMAIL] --role roles/compute.imageUser

Get Internal DNS address of a GCE instance

curl "" \
    -H "Metadata-Flavor: Google"

Authenticate with service account

gcloud auth activate-service-account --key-file="/path/to/key_file.json"

All about roles

Complete list of GCP roles and their permissions.