Transfer files to Linux VMs

Linux

To transfer files to Compute Engine VM instances, different options areavailable depending on your workstation OS and the targetVM instance OS.

Transfer fromTo Linux VMs
Linux or macOS
Windows

Transfer files through Cloud Storage

Cloud Storage buckets can be used as a transfer point between you and your VMs. You can use a web browser, the Google Cloud CLI, or a programming language to transfer files between Cloud Storage and Compute Engine VMs.

Different credential types can be used for the upload and download step to best suit your needs:

To use Cloud Storage to transfer files between a computer and a VM, do the following:

  1. Create a Cloud Storage bucket if you don't have an existing bucket to use for file transfers.
  2. Use IAM permissions to modify the access to the bucket:
    • Accounts uploading file(s) to the bucket should have theStorage Object Admin granted.
    • Accounts downloading file(s) should have theStorage Object Viewer role granted.
  3. Log in to the source device andupload the files to the bucket.
  4. Log in to the destination device anddownload the files from the bucket completing the file transfer.
  5. Optional:Delete files that you no longer need to prevent any unwanted storage charges.

If you need to transfer files in the other direction, you can reverse the process. Ensure that the account uploading the file has write access to the bucket.

Transfer files using SSH-in-browser

If you can establish an SSH connection to a VM by usingSSH-in-browser,you can use that connection to transfer files to and from the VM.

Upload to the VM

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. In the list of virtual machine instances, clickSSH in the row of the instance that you want to connect to.

    SSH button next to instance name.

  3. After the connection is established, click the upload icon.

    The upload dialog opens.

  4. Choose the files to upload.
  5. Upload the files by clickingUpload Files. The fileuploads to your/home/USER directory.

Download from the VM

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. In the list of virtual machine instances, clickSSH in the row of the instance that you want to connect to.

    SSH button next to instance name.

  3. After the connection is established, click the download icon.

    The download dialog opens.

  4. In thePath field, enter the relative path of the file to download.
  5. Download the file by clickingDownload. The filedownloads to the default download folder of your workstation.

Transfer files using the Google Cloud CLI

Google Cloud CLI provides a Secure Copy Protocol (SCP) file transfer utility over an established SSH connection.

To transfer files using SCP, do the following:

  1. Review your firewall rules and confirm that SSH connections in on port22 are permitted; if notcreate a SSH firewall rule.
  2. Ensuregcloud CLI is installed on the source device containing the files to be transferred.
  3. Use thegcloud compute scp command to transfer the files to the destination machine.

The following example copies a file from your workstation to the home directory of the VM:

gcloud compute scpLOCAL_FILE_PATHVM_NAME:REMOTE_DIR

Replace the following:

  • LOCAL_FILE_PATH: the path to the file on your machine
  • VM_NAME: the name of your VM
  • REMOTE_DIR: a directory on the remote machine

You can also copy files and directories in reverse from the remote machine. Thefollowing example recursively copies a directory from the source to the destination:

gcloud compute scp --recurseVM_NAME:REMOTE_DIRLOCAL_FILE_PATH

For more information, see thegcloud compute scp reference documentation.

Transfer files using SCP on Linux and macOS workstations

Thescp command-line tool works similarly to thegcloud compute scp command but requires you tomanually manage your SSH keys.

To transfer files using SCP, you must have a firewall rule on the networkthat your VM uses that allows SSH connections on port22. You can verifythat this firewall rules exists by looking for a firewall rule that allowstcp:22 connections in the Google Cloud console.

Go to Firewall rules

If you don't have a firewall rule that allows SSH connections on port22,create the firewall rule.

Thescp tool uses the same key files that you use toconnect to your instances using standard SSH.

  1. If you have not yet applied a public key to your Google Cloud consoleproject or VM instance,create an SSH key pair andadd the public key to project or instance metadata.

  2. Find the external IP for the VM that you want to send files to.

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. In the list of VMs, find the external IP address in theExternal IPcolumn for the target VM.

  3. Use thescp tool to copy a file from your workstation to the homedirectory of the target VM. For this example, the private key is at~/.ssh/my-ssh-key.

    scp -i ~/.ssh/my-ssh-keyLOCAL_FILE_PATHUSERNAME@IPv4_ADDRESS:~

    For an external IPv6 address, use the following syntax:

    scp -6 -i ~/.ssh/IDENTITY_FILELOCAL_FILE_PATHUSERNAME@[IPv6_ADDRESS]:~/

    Replace the following:

    • IDENTITY_FILE: the file containing the identity(private key) for public key authentication
    • LOCAL_FILE_PATH: the name of the local filethat you want to upload
    • USERNAME: your username
    • IPv4_ADDRESS orIPv6_ADDRESS: the external IP address for your VM

You can also copy files from a VM to your local workstation by reversingthe source and destination variables. For this example, copy a file from yourVM to a path on your workstation.

scp -i ~/.sshIDENTITY_FILEUSERNAME@IP_ADDRESS:REMOTE_FILE_PATHLOCAL_FILE_PATH

Replace the following:

  • IDENTITY_FILE: the file containing the identity(private key) for public key authentication
  • USERNAME: your username
  • IP_ADDRESS: the external IP address for your VM
  • REMOTE_FILE_PATH: the name of the remote file thatyou want to download
  • LOCAL_FILE_PATH: the location on your workstationwhere you want to download the file to

Transfer files using WinSCP on Windows workstations

On Windows workstations, the WinSCP client lets you manage files on yourinstances through a graphical file browser interface.

WinSCP uses the same key files that you use toconnect to VMs using PuTTY.

  1. Do the following if you haven't configured key-based SSH authentication for your instance:

    1. Create an SSH key pair using PuTTYgen.The private ssh key must use the.ppk format, which is the defaultfor keys created by PuTTYgen.

    2. Add your public SSH key to your project's metadata or to your VM's metadata.For more information, seeAdd SSH keys to project metadataorAdd SSH keys to instance metadata.

  2. Find the external IP for the VM that you want to send files to.

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. In the list of VMs, find the external IP address in theExternal IP columnfor your VM.
  3. Download and install WinSCP.The default install settings work for most users.

  4. Start the WinSCP program. A login window opens where you can configureyour connection settings.

  5. In WinSCP, configure your connection settings.

    1. SelectSCP as the file transfer protocol in theFile protocol field.

    2. In theHost Name field, specify the external IP address for the VM that you want to connect to.

    3. In theUser name field, specify the Google username that you use to access your project. For this example, the user isexample-user.

      Setting the file protocol to SCP, the hostname to 104.196.31.103, and the username to example-user.

  6. Click theAdvanced drop-down list to open the advanced settings, andnavigate toSSH >Authentication.

  7. In thePrivate key file box, specify the path to your privatekey file of theSSH key pair that you created for the VM.

    Setting the private key file to my-ssh-key.ppk in the Advanced Site Settings dialog.

  8. ClickOk to save the advanced settings.

  9. ClickLogin to connect to your VM. If the connection issuccessful, the window opens your local file system on the left andthe VM's file system on the right. You can navigate to differentdirectories in these file systems and drag files to transfer them toand from your VM.

  10. You likely don't have permission to manage most files outside of your homedirectory of the VM. Navigate to the home directory of the VM:

    /home/USERNAME
  11. Use the WinSCP interface to move files between your workstation and theVM.

  12. After you copy your files to the VM,connect to your instance so that you can execute or move files with fullsudo permissions.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.