To transfer files from a Google Compute Engine (GCE) instance to your local computer, use the gcloud compute scp command. This allows you to securely copy files over SSH.

Prerequisites

Before using the command, make sure:

  • Google Cloud SDK is installed and configured on your local machine.
  • Install guide

  • SSH access is enabled for your VM. The SDK usually handles SSH keys automatically.
  • Firewall rules allow SSH (port 22) on your GCE instance.

Copying a Single File

Use this command to copy a file from your VM to your local machine:
gcloud compute scp INSTANCE_NAME:~/remote-file.txt ~/local-directory/

Replace:

  • INSTANCE_NAME → your GCE VM instance name
  • remote-file.txt → the name or path of the file on the VM
  • ~/local-directory/ → the destination folder on your local machine

Copying an Entire Directory

To copy a whole folder (and its contents), add the –recurse flag:
gcloud compute scp --recurse INSTANCE_NAME:~/remote-directory/ ~/local-directory/

This copies everything inside remote-directory to your local machine.

Example Command

Here’s a real working example that copies .bashrc from a VM named vm1 to your local Documents folder:

gcloud compute scp vm1:~/.bashrc ~/Documents/

If the previous commands don’t work due to zone or other issues, try adding the –zone flag:
gcloud compute scp vm1:~/.bashrc ~/Documents/ –zone=us-central1-a

Tips

-> To avoid typing the zone every time, set a default:
gcloud config set compute/zone us-central1-a

Need Help With Cloud Development?

Work with our skilled Cloud developers to accelerate your project and boost its performance.

Hire Cloud Developers

Support On Demand!

Related Q&A