Copying from Virtual Machine onto Local Computer

I’ve been trying to figure out how to copy files from my Virtual Machine environment onto my local computer and desktop. I’m still trying to understand it completely, but according to my DevTech professor, you can use the “scp” command.

This is my professor explaining it (I’ll add commentary once I understand everything):

You can transfer the file to your own computer with secure copy (scp).  It is part of the OpenSSH Suite and is used to transfer files back and forth between machines.  It is like ssh but for file transfer. You will need to include a flag to your local ssh key file.

Here is an online example I found explaining it as well: https://uoa-eresearch.github.io/vmhandbook/doc/copy-file-linux.html

More explanation by my professor: 

From “man scp”, the syntax is:

SYNOPSIS
     scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]
         [-l limit] [-o ssh_option] [-P port] [-S program] source … target

Square brackets contain options, and they are optional (because they are in square brackets).

The only required option is: scp source target.

You can copy from remote server (VM in this case) to your local computer, or from your local computer to the VM.  This will determine what is “source” and what is “target”.  For example, to copy something from your local computer to the VM (with -i because we need to pass our ssh key because we configured the VM to authenticate this way):

scp    -i /path/to/your/private-key    file-on-local-computer    [email protected]

-i should point to your private ssh key

where username is your VM username, and 12.34.56.78 is your VM external IP address.  To copy in reverse, you reverse the source and target.  If you use scp on the VM then the source/target are relative to the VM.

scp script.sh ~/. will copy the script locally, because “script.sh” is source and “~/.” is target, and this target is local, not remote.  Your VM is remote, it is far away somewhere.  Just like you log into your VM with ssh, scp needs username and IP address to connect to it, this is what defines it as remote.

Another example is uploading your homework to Courseworks.  Courseworks is remote, you can’t access it as you would a local directory on your computer.  You log in, then you upload the file through the web interface.  ssh/scp is just a different interface, in this case for managing (ssh) and moving files (scp) between two different hosts.

0 comments on “Copying from Virtual Machine onto Local ComputerAdd yours →

Leave a Reply

Your email address will not be published.