gcloud compute scp [[USER@]INSTANCE:]SRC [[[USER@]INSTANCE:]SRC …] [[USER@]INSTANCE:]DEST [--compress] [--dry-run] [--force-key-file-overwrite] [--plain] [--port=PORT] [--recurse] [--scp-flag=SCP_FLAG] [--ssh-key-file=SSH_KEY_FILE] [--strict-host-key-checking=STRICT_HOST_KEY_CHECKING] [--zone=ZONE] [--internal-ip | --tunnel-through-iap] [--network=NETWORK --region=REGION : --dest-group=DEST_GROUP] [--ssh-key-expiration=SSH_KEY_EXPIRATION | --ssh-key-expire-after=SSH_KEY_EXPIRE_AFTER] [GCLOUD_WIDE_FLAG …]
gcloud compute scp securely copies files between a virtual machine
instance and your local machine using the scp command.
This command works for Linux VMs and Windows Server 2019 and later VMs that have SSH enabled.
In order to set up a successful transfer, follow these guidelines:
example-instance:~/FILE).
FILE).
Under the covers, scp(1) is used to facilitate the transfer.
--region and --network flags are provided, then
--plain and --tunnel-through-iap are implied and any
remote file names must be prefixed with the remote IP address instead of the
instance name. This is most useful for connecting to on-prem resources.
~/narnia, from
example-instance to the
~/wardrobe directory of your local host, run:
gcloud compute scp --recurse example-instance:~/narnia ~/wardrobeConversely, files from your local computer can be copied to a virtual machine:
gcloud compute scp ~/localtest.txt ~/localtest2.txt example-instance:~/narniaRemote Windows-based virtual machines require you to provide a path using backslash notation:
gcloud compute scp ~/localtest.txt ~/localtest2.txt example-windows-instance:"C:\Users\Public"Paths for remote Windows-based virtual machines which contain spaces in directory name should be appropriately protected with a pair of nested single and double quotes:
gcloud compute scp ~/localtest.txt 'example-windows-instance:"C:\Users\Public\Test Folder"'
If the zone cannot be determined, you will be prompted for it. Use the
--zone flag to avoid being prompted:
gcloud compute scp --recurse example-instance:~/narnia ~/wardrobe --zone=us-central1-aTo specify the project, zone, and recurse all together, run:
gcloud compute scp --project="my-gcp-project" --zone="us-east1-b" --recurse ~/foo-folder/ gcp-instance-name:~/You can limit the allowed time to ssh. For example, to allow a key to be used through 2019:
gcloud compute scp --recurse example-instance:~/narnia ~/wardrobe --ssh-key-expiration="2020-01-01T00:00:00:00Z"Or alternatively, allow access for the next two minutes:
gcloud compute scp --recurse example-instance:~/narnia ~/wardrobe --ssh-key-expire-after=2m
To use the IP address of your remote VM (eg, for on-prem), you must also specify
the --region and --network flags:
gcloud compute scp 10.1.2.3:~/narnia ~/wardrobe --region=us-central1 --network=defaultUSER@]INSTANCE:]SRC [[[USER@]INSTANCE:]SRC …]USER@]INSTANCE:]DEST--compress--dry-run--force-key-file-overwrite--plainssh(1)/scp(1)
flags. This flag is useful if you want to take care of authentication yourself
or use specific ssh/scp features.
--port=PORT--recurse--scp-flag=SCP_FLAG--ssh-key-file=SSH_KEY_FILE~/.ssh/google_compute_engine.
--strict-host-key-checking=STRICT_HOST_KEY_CHECKINGSTRICT_HOST_KEY_CHECKING must be one of:
yes, no, ask.
--zone=ZONE
If not specified and the
property isn't set, you might be prompted to select a zone (interactive mode
only).
compute/zone
To avoid prompting when this flag is omitted, you can set the
property:
compute/zone
gcloud config set compute/zone ZONEA list of zones can be fetched by running:
gcloud compute zones listTo unset the property, run:
gcloud config unset compute/zoneCLOUDSDK_COMPUTE_ZONE.
At most one of these can be specified:
--internal-ipFor this connection to work, you must configure your networks and firewall to allow SSH connections to the internal IP address of the instance to which you want to connect.
To learn how to use this flag, see https://cloud.google.com/compute/docs/instances/connecting-advanced#sshbetweeninstances.--tunnel-through-iap--network=NETWORK--region=REGION--dest-group=DEST_GROUP--ssh-key-expiration=SSH_KEY_EXPIRATION--ssh-key-expire-after=SSH_KEY_EXPIRE_AFTER--access-token-file,
--account, --billing-project,
--configuration,
--flags-file,
--flatten, --format, --help, --impersonate-service-account,
--log-http,
--project, --quiet, --trace-token, --user-output-enabled,
--verbosity.
Run $ gcloud help for details.
gcloud alpha compute scpgcloud beta compute scpgcloud preview compute scp
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-05-27 UTC.