Upload Local Files to Gcp Vm Instance
Linux
To transfer files to Compute Engine VM instances, different options are bachelor depending on your workstation OS and the target VM instance OS.
| Transfer from | To Linux VMs |
|---|---|
| Linux or macOS |
|
| Windows |
|
Transfer files through Cloud Storage
Cloud Storage buckets can be a convenient intermediate transfer point between you and your VMs.
This file transfer method works on about all operating systems and VM types as long as your VM has admission to your Cloud Storage bucket through a service account or through your personal user credentials.
Upload your files from your workstation to a Deject Storage bucket. Then, download those files from the bucket to your instances.
- Create a Cloud Storage bucket or identify an existing saucepan that you want to use to transfer files.
- From your workstation, upload files to the bucket.
- Connect to your VM using SSH.
- On your VM, download files from the saucepan.
If you demand to transfer files in the other direction, opposite the process. Upload the files from your VM, and then download those files to your workstation.
Transfer files using SSH in the browser
If y'all tin institute an SSH connection to a VM using the SSH from the Browser window, yous tin use that connexion to transfer files to the VM.
- In the Cloud Console, go to the VM instances page.
Become to VM instances
- In the list of virtual automobile instances, click SSH in the row of the instance that you lot want to connect to.
- Subsequently the connection is established, click the gear icon in the upper right 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 y'all want to transfer.
If yous uploaded a file, the file is in your /abode/USER directory.
If you downloaded a file, the file is in the default download binder on your local workstation.
Transfer files using the Google Deject CLI
The Google Deject CLI provides an SCP file transfer utility, creating an SSH central pair for you the first time you connect. Your individual key is stored on your local device and its corresponding public primal is copied to project or VM instance metadata.
To transfer files using SCP, you must have 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 Cloud Panel.
Become to Firewall rules
If y'all don't have a firewall rule that allows SSH connections on port 22, create the firewall dominion.
Yous tin install the gcloud CLI and utilise it to re-create files and directories to your VM using the scp command.
The following example copies a file from your workstation to the home 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 proper name of your VM
You can too copy files and directories from a VM to your local workstation. The post-obit example 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 proper noun of the VM -
REMOTE_DIR: the path to the directory on your VM -
LOCAL_DIR: the path where you lot want to put the directory on your workstation
For more information, come across the gcloud compute scp reference documentation.
Transfer files using SCP on Linux and macOS workstations
The scp control-line tool works similarly to the gcloud compute scp command but requires you lot to manually manage your SSH keys.
To transfer files using SCP, you must have a firewall rule on the network that your VM uses that allows SSH connections on port 22. You lot can verify that this firewall rules exists by looking for a firewall rule that allows tcp:22 connections in the Google Cloud Panel.
Go to Firewall rules
If you lot don't have a firewall rule that allows SSH connections on port 22, create the firewall dominion.
The scp tool uses the same cardinal files that y'all use to connect to your instances using standard SSH.
-
If you accept non yet applied a public fundamental to your Google Cloud Console project or VM instance, create an SSH key pair and add the public fundamental to project or example metadata.
-
Observe the external IP for the VM that you desire to transport files to. In the Google Deject Console, go to the VM instances page.
Go to VM instances
-
Use the
scptool to copy a file from your workstation to the habitation directory of the target VM. For this case, the private central is at~/.ssh/my-ssh-key.scp -i ~/.ssh/my-ssh-cardinal LOCAL_FILE_PATH USERNAME@IP_ADDRESS:~
Replace the following:
-
LOCAL_FILE_PATH: the proper noun of the local file that you want to upload -
USERNAME: your username -
IP-Address: the external IP address for your VM
-
You tin as well copy files from a VM to your local workstation by reversing the source and destination variables. For this instance, copy a file from your VM to a path on your workstation.
scp -i ~/.ssh/my-ssh-central USERNAME@IP_ADDRESS:REMOTE_FILE_PATH LOCAL_FILE_PATH
Replace 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 desire to download -
LOCAL_FILE_PATH: the location on your workstation where 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 your instances through a graphical file browser interface.
WinSCP uses the same key files that y'all apply to connect to your instances using PuTTY.
-
Do the following if y'all oasis't configured key-based SSH authentication for your instance:
-
Create an SSH key pair.
-
Add your public SSH cardinal to your projection's metadata or to your VM'south metadata. For more information, encounter Add together SSH keys to project metadata or Add SSH keys to instance metadata.
-
-
Find the external IP for the VM that you want to send files to.
- In the Google Cloud Panel, become to the VM instances page.
Go to VM instances
- In the list of VMs, find the external IP address in the External IP column for your VM.
- In the Google Cloud Panel, become to the VM instances page.
-
Download and install WinSCP. The default install settings piece of work for most users.
-
Start the WinSCP program. A login window opens where you can configure your connection settings.
-
In WinSCP, configure your connection settings.
-
Select
SCPas the file transfer protocol in the File protocol field. -
In the Host Proper noun field, specify the external IP accost for the VM that you want to connect to.
-
In the User name field, specify the Google username that you utilize to access your project. For this case, the user is
instance-user.
-
-
Click the Avant-garde drib-down listing to open up the advanced settings, and navigate to SSH > Authentication.
-
In the Private central 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 system on the left and the VM'south file organization on the right. You lot can navigate to different directories in these file systems and drag files to transfer them to and from your VM.
-
Y'all likely do not have permission to manage most files outside of your home directory of the VM. Navigate to the dwelling directory of the VM:
/home/USERNAME
-
Apply the WinSCP interface to move files between your workstation and the VM.
-
After y'all copy your files to the VM, connect to your instance so that you can execute or move files with full
sudopermissions.
What's next
- Connect to your instances to use the files that yous uploaded.
Source: https://cloud.google.com/compute/docs/instances/transfer-files
0 Response to "Upload Local Files to Gcp Vm Instance"
Publicar un comentario