Transfer files to Linux VMs  |  Compute Engine Documentation  |  Google Cloud (2024)

Linux

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

Transfer from To Linux VMs
Linux or macOS
  • Cloud Storage
  • Google Cloud CLI
  • SSH-in-browser
  • SCP
Windows
  • Cloud Storage
  • Google Cloud CLI
  • WinSCP

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:

  • User account credentials are best for single use operations, or resources that you are primarily responsible for.
  • Consider service account credentials for scaled deployments and shared resource scenarios.

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 the Storage Object Admin granted.
    • Accounts downloading file(s) should have the Storage Object Viewer role granted.
  3. Login to the source device and upload the files to the bucket.
  4. Login to the destination device and download 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, click SSH in the row of the instance that you want to connect to.

    Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (1)

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

    Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (2)

    The upload dialog opens.

  4. Choose the file(s) to upload.
  5. Upload the file(s) by clicking Upload 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, click SSH in the row of the instance that you want to connect to.

    Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (3)

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

    Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (4)

    The download dialog opens.

  4. In the Path textbox, enter the relative file path of the file todownload.
  5. Download the file by clicking Download. 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 port 22 are permitted; if not create a SSH firewall rule.
  2. Ensure gcloud CLI is installed on the source device containing the files to be transferred.
  3. Use the gcloud 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 scp LOCAL_FILE_PATH VM_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 --recurse VM_NAME:REMOTE_DIR LOCAL_FILE_PATH

For more information, see the gcloud compute scp reference documentation.

Transfer files using SCP on Linux and macOS workstations

The scp 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 port 22. 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 port 22,create the firewall rule.

The scp 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. In theGoogle Cloud console, go to the VM instances page.

    Go to VM instances

  3. Use the scp 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-key LOCAL_FILE_PATH USERNAME@IP_ADDRESS:~

    Replace the following:

    • LOCAL_FILE_PATH: the name of the local filethat you want to upload
    • USERNAME: your username
    • IP-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 ~/.ssh/my-ssh-key USERNAME@IP_ADDRESS:REMOTE_FILE_PATH LOCAL_FILE_PATH

Replace the following:

  • 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 the VM instances page.

      Go to VM instances

    2. In the list of VMs, find the external IP address in the External 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. Select SCP as the file transfer protocol in the File protocol field.

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

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

      Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (5)

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

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

    Transfer files to Linux VMs | Compute Engine Documentation | Google Cloud (6)

  8. Click Ok to save the advanced settings.

  9. Click Login 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 do not 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 full sudo permissions.

What's next

  • Connect to your instancesto use the files that you uploaded.
Transfer files to Linux VMs  |  Compute Engine Documentation  |  Google Cloud (2024)

FAQs

Transfer files to Linux VMs  |  Compute Engine Documentation  |  Google Cloud? ›

To transfer a file from the physical computer to the virtual machine, simply drag it to the virtual machine window (where the guest OS is displayed). You can also right-click "Copy" on the physical computer and right-click "Paste" in the guest OS.

How to transfer files to Linux VM? ›

3. Transfer Files Using VirtualBox
  1. Access the guest machine settings:
  2. In the guest machine settings, go to the Shared Folders section.
  3. Click the icon corresponding to the label Add new shared folder.
  4. In the pop window, select or enter the host (Linux) target folder path in Folder Path.
  5. Check the Auto-mount checkbox.
Feb 21, 2023

How do I connect my Linux VM to Google Cloud? ›

Connect to VMs
  1. In the Google Cloud console, activate Cloud Shell. Activate Cloud Shell. At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. ...
  2. Run the following command: gcloud compute ssh --project= PROJECT_ID --zone= ZONE VM_NAME.

How do I transfer a file to a virtual machine? ›

To transfer a file from the physical computer to the virtual machine, simply drag it to the virtual machine window (where the guest OS is displayed). You can also right-click "Copy" on the physical computer and right-click "Paste" in the guest OS.

How do I export a VM from Google Cloud? ›

Export a pre-filled CSV file
  1. Open the Migrate to Virtual Machines page in the Google Cloud console.
  2. To export a list of source VMs: Select the Sources tab. Select the source VMs you would like to export from the inventory. ...
  3. To export groups of existing migrations: Select the Groups tab.

How do I import a VM into Google Cloud? ›

  1. In the Google Cloud console, upload the virtual disk file to Cloud Storage.
  2. Go to the Create an image page. ...
  3. Specify a Name for your image.
  4. Under Source, select Virtual disk (VMDK, VHD, ...).
  5. Browse to or manually input the storage location for the Cloud Storage file.
  6. Under operating system, select No operating system.

What is the best way to connect to a Linux VM? ›

SSH with a new key pair
  1. Locate your private SSH Key.
  2. Run the SSH command with the following syntax: ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP. For example, if your azureuser is the username you created and 20.51.230.13 is the public IP address of your VM, type: ...
  3. Validate the returned fingerprint. ...
  4. Success!

How do I migrate a VM to Google Cloud? ›

  1. Design the migration to Google Cloud.
  2. Assess the source environment and workloads.
  3. Build your foundation. Build the foundation on Google Cloud. Prepare the source environment.
  4. Migrate your VMs. Structure of a Migrate to Virtual Machines migration. ...
  5. Optimize your environment after migration.

Which command is used to transfer files between VMs? ›

SCP. SCP is a common tool for secure copy files between a local and remote machine. It uses the same authentication and security as SSH. You need a SCP client which is included in Bash shell of most Linux distributions and Mac computers and PowerShell.

How to transfer files from Windows to Linux using command line? ›

Steps to Transfer Files from Windows to Linux Using Command Prompt. Search cmd in the search bar, and double-click the Command Prompt to open it. Or press the Windows key + R, then type cmd or cmd.exe in the Run command box, and press Enter. Then, you should see the command prompt interface as below.

How do I copy something to a virtual machine? ›

Right-click and select Copy, or press Ctrl+C to copy the text. In the VM, click where you want to paste the text. Press Ctrl+V. There may be a short delay after you press Ctrl+V before the text is pasted.

How do I transfer data from Google Cloud? ›

Transferring Data with Google Cloud Storage Buckets
  1. Check for gcloud​ Open a terminal and navigate to your data's destination. ...
  2. Install gcloud​ ...
  3. Export Your Google Credentials​ ...
  4. List Files in a GCS Bucket​ ...
  5. Transfer a File To/From a GCS Bucket​ ...
  6. Delete a File From a GCS Bucket​

How do I access my VM on Google Cloud? ›

Log in to your Google Cloud account. Navigate to Compute > Compute Engine > VM instances. Click the newly created VM instance to open the VM instance details window.

How do I connect Google cloud storage to VM instance? ›

In the Google Cloud console, go to the VM instances page. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to. After the connection is established, click the upload icon upload.

How do I transfer files from PC to VMware Linux? ›

Transferring Files via the Command Line
  1. Open the Command Prompt or PowerShell in your Windows host system.
  2. Use the "cd" command to navigate to the directory containing the file you want to transfer.
  3. Use the "scp" command to copy the file to the VMware Ubuntu virtual machine, specifying the destination path.
Jan 11, 2024

Can Windows files be transferred to Linux? ›

4 Ways to Transfer Files From Windows to Linux

Securely copy files via SSH. Windows to Linux file transfer with FTP. Share data using sync software. Use shared folders in your Linux virtual machine.

How can files be transferred between Linux server? ›

In addition to transferring to or from the current server, use SCP to move files between two remote Linux machines. To do so, run the command on your local computer with their address as the source and destination. If you have multiple projects hosted on different remote machines, doing this helps improve efficiency.

Top Articles
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 6470

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.