Google Compute Engine scp Files on a Linux or Unix or Mac OS X

ht‮pt‬s://www.lautturi.com
Google Compute Engine scp Files on a Linux or Unix or Mac OS X

To copy files to or from a Google Cloud Compute Engine instance using the scp command, you will need to use the instance's public IP address and the SSH key pair that you specified when you created the instance.

Here are the steps to use scp to copy files to or from a Google Cloud Compute Engine instance:

  1. Connect to the instance using ssh:
ssh -i path/to/private_key username@public_ip_address

Replace "path/to/private_key" with the path to the private key file and "username" with the username for the instance. Replace "public_ip_address" with the public IP address of the instance.

  1. To copy a file from your local machine to the instance, use the following scp command:
scp -i path/to/private_key local_file username@public_ip_address:remote_file

Replace "path/to/private_key" with the path to the private key file, "local_file" with the path to the file on your local machine, "username" with the username for the instance, and "remote_file" with the path to the destination file on the instance.

For example, to copy a file named "file.txt" from the current directory to the home directory of the instance, you can use the following command:

scp -i private_key file.txt user@1.2.3.4:~/file.txt
  1. To copy a file from the instance to your local machine, use the following scp command:
scp -i path/to/private_key username@public_ip_address:remote_file local_file

Replace "path/to/private_key" with the path to the private key file, "username" with the username for the instance, "remote_file" with the path to the file on the instance, and "local_file" with the path to the destination file on your local machine.

For example, to copy a file named "file.txt" from the home directory of the instance to the current directory on your local machine, you can use the following command:

scp -i private_key user@1.2.3.4:~/file.txt .
Created Time:2017-10-28 20:40:39  Author:lautturi