Stay organized with collections Save and categorize content based on your preferences.
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.
If the --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 ~/wardrobe
Conversely, files from your local computer can be copied to a virtual machine:
gcloud compute scp ~/localtest.txt ~/localtest2.txt example-instance:~/narnia
Remote 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-a
To 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=default
USER
@]INSTANCE
:]SRC
[[[USER
@]INSTANCE
:]SRC
…]
USER
@]INSTANCE
:]DEST
--compress
--dry-run
--force-key-file-overwrite
If disabled, the files associated with a broken SSH key will not be regenerated and will fail in both interactive and non-interactive environments.
--plain
ssh(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_CHECKING
STRICT_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 ZONE
A list of zones can be fetched by running:
gcloud compute zones list
To unset the property, run:
gcloud config unset compute/zone
Alternatively, the zone can be stored in the environment variable
.CLOUDSDK_COMPUTE_ZONE
--internal-ip
For 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
To learn more, see the IAP for TCP forwarding documentation.
--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 scp
gcloud beta 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 2025-05-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4