Gcp Compute Engine How to Upload Files
Linux
To transfer files to Compute Engine VM instances, different options are available depending on your workstation Os and the target VM case OS.
| Transfer from | To Linux VMs |
|---|---|
| Linux or macOS |
|
| Windows |
|
Transfer files through Deject Storage
Deject Storage buckets tin can be a convenient intermediate transfer signal between you and your VMs.
This file transfer method works on almost all operating systems and VM types as long as your VM has access to your Cloud Storage bucket through a service account or through your personal user credentials.
Upload your files from your workstation to a Cloud Storage bucket. And so, download those files from the bucket to your instances.
- Create a Cloud Storage saucepan or identify an existing bucket that you want to utilise to transfer files.
- From your workstation, upload files to the saucepan.
- Connect to your VM using SSH.
- On your VM, download files from the bucket.
If you need to transfer files in the other direction, reverse the process. Upload the files from your VM, and and so download those files to your workstation.
Transfer files using SSH in the browser
If you can institute an SSH connection to a VM using the SSH from the Browser window, you can use that connection to transfer files to the VM.
- In the Cloud Panel, go to the VM instances folio.
Go to VM instances
- In the list of virtual auto instances, click SSH in the row of the instance that yous desire to connect to.
- After the connection is established, click the gear icon in the upper correct of the SSH from the Browser window and select Upload file. Alternatively, select Download file to download a file from the VM.
- The transfer dialog opens. Specify which file you want to transfer.
If you uploaded a file, the file is in your /home/USER directory.
If you downloaded a file, the file is in the default download folder on your local workstation.
Transfer files using the Google Cloud CLI
The Google Cloud CLI provides an SCP file transfer utility, creating an SSH central pair for you lot the showtime time you connect. Your private key is stored on your local device and its corresponding public key is copied to project or VM instance metadata.
To transfer files using SCP, y'all must accept a firewall rule on the network that your VM uses that allows SSH connections on port 22. You can verify that this firewall rules exists by looking for a firewall rule that allows tcp:22 connections in the Google Deject Console.
Become to Firewall rules
If y'all don't take a firewall rule that allows SSH connections on port 22, create the firewall rule.
Y'all can install the gcloud CLI and use it to copy files and directories to your VM using the scp command.
The following example copies a file from your workstation to the abode directory of the VM.
gcloud compute scp LOCAL_FILE_PATH VM_NAME:~
Replace the following:
-
LOCAL_FILE_PATH: the path to the file on your workstation -
VM_NAME: the name of your VM
Yous tin besides copy files and directories from a VM to your local workstation. The following case recursively copies a directory from your VM (the source) to your local workstation (the destination).
gcloud compute scp --recurse VM_NAME:REMOTE_DIR LOCAL_DIR
Replace the following:
-
VM_NAME: the name of the VM -
REMOTE_DIR: the path to the directory on your VM -
LOCAL_DIR: the path where y'all want to put the directory on your workstation
For more than 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 the gcloud compute scp command but requires y'all to manually manage your SSH keys.
To transfer files using SCP, you must take a firewall rule on the network that your VM uses that allows SSH connections on port 22. You lot tin can verify that this firewall rules exists by looking for a firewall rule that allows tcp:22 connections in the Google Deject Console.
Become to Firewall rules
If you don't have a firewall dominion that allows SSH connections on port 22, create the firewall rule.
The scp tool uses the same fundamental files that you lot use to connect to your instances using standard SSH.
-
If you have not yet applied a public primal to your Google Cloud Console project or VM instance, create an SSH cardinal pair and add together the public central to project or example metadata.
-
Find the external IP for the VM that you desire to send files to. In the Google Cloud Panel, go to the VM instances page.
Go to VM instances
-
Use the
scptool to re-create a file from your workstation to the home directory of the target VM. For this example, the individual primal is at~/.ssh/my-ssh-cardinal.scp -i ~/.ssh/my-ssh-key LOCAL_FILE_PATH USERNAME@IP_ADDRESS:~
Replace the following:
-
LOCAL_FILE_PATH: the name of the local file that y'all want to upload -
USERNAME: your username -
IP-Accost: the external IP address for your VM
-
You lot can also copy files from a VM to your local workstation past reversing the source and destination variables. For this example, copy a file from your VM to a path on your workstation.
scp -i ~/.ssh/my-ssh-cardinal USERNAME@IP_ADDRESS:REMOTE_FILE_PATH LOCAL_FILE_PATH
Supplant the post-obit:
-
USERNAME: your username -
IP_ADDRESS: the external IP address for your VM -
REMOTE_FILE_PATH: the name of the remote file that you want to download -
LOCAL_FILE_PATH: the location on your workstation where you desire to download the file to
Transfer files using WinSCP on Windows workstations
On Windows workstations, the WinSCP client lets you manage files on your instances through a graphical file browser interface.
WinSCP uses the same key files that yous utilise to connect to your instances using PuTTY.
-
Practice the following if y'all haven't configured key-based SSH authentication for your instance:
-
Create an SSH key pair.
-
Add your public SSH key to your projection'south metadata or to your VM's metadata. For more data, see Add together SSH keys to project metadata or Add together SSH keys to instance metadata.
-
-
Find the external IP for the VM that y'all want to send files to.
- In the Google Cloud Panel, go to the VM instances folio.
Get to VM instances
- In the list of VMs, find the external IP accost in the External IP column for your VM.
- In the Google Cloud Panel, go to the VM instances folio.
-
Download and install WinSCP. The default install settings work for most users.
-
Offset the WinSCP program. A login window opens where you tin can configure your connection settings.
-
In WinSCP, configure your connection settings.
-
Select
SCPevery bit the file transfer protocol in the File protocol field. -
In the Host Name field, specify the external IP address for the VM that you want to connect to.
-
In the User proper noun field, specify the Google username that you lot use to access your project. For this instance, the user is
example-user.
-
-
Click the Advanced drop-down list to open the avant-garde settings, and navigate to SSH > Authentication.
-
In the Private key file box, specify the path to your individual key file of the SSH fundamental pair that you created for the VM.
-
Click Ok to save the advanced settings.
-
Click Login to connect to your VM. If the connection is successful, the window opens your local file organization on the left and the VM's file system on the correct. You can navigate to different directories in these file systems and drag files to transfer them to and from your VM.
-
You lot likely do not have permission to manage most files outside of your home directory of the VM. Navigate to the home directory of the VM:
/home/USERNAME
-
Use the WinSCP interface to move files betwixt your workstation and the VM.
-
After you copy your files to the VM, connect to your case and so that you lot tin execute or move files with total
sudopermissions.
What's next
- Connect to your instances to utilise the files that you uploaded.
Source: https://cloud.google.com/compute/docs/instances/transfer-files#:~:text=In%20the%20Cloud%20Console%2C%20go%20to%20the%20VM%20instances%20page.&text=In%20the%20list%20of%20virtual,window%20and%20select%20Upload%20file.
0 Response to "Gcp Compute Engine How to Upload Files"
Post a Comment