How to copy files from/to a Linux VM

copy-files-from-linux-vm

Howdy guys, if we are working on Cloud VMs, there are high chances that you will need to copy files from/to a Linux VM. The most preferred way of doing this is using FTP, you can any use any FTP client like Filezilla to achieve it.

Now in some cases, you might not have the FTP ports opened on your site, you only have SSH access to it, then we have good news for you, you can copy files without opening any extra port for FTP.

This can be achieved by SCP(Secure Copy Protocol). Secure copy protocol (SCP) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. 

Copy files with SCP

SCP command:- Sending files between linux systems quickly and easily!!. . –  Do With Tech

Linux and macOS systems by default come with a command line SCP client. Windows SCP client is available in MobaXterm and Git bash.

There are a lot of in-detail manuals for the scp command to be found on the Internet, here is a quick guide on how to use it normally:

# Upload the file yourFile.xyz to your home directory on the VM
$ scp yourFile.xyz username@dowithtech.its.india.ac.in:~/.
 
# Upload the folder yourFolder to your home directory on the VM
$ scp -r yourFolder username@dowithtech.its.india.ac.in:~/.

Downloading files from your home directory on the login node to your home directory on your local machine is a similar process as shown below:

# Download the file ~/yourFile.xyz to your home directory on your computer
$ scp username@dowithtech.its.india.ac.in:~/yourFile.xyz ~/.
 
# Download the folder yourFolder to your home directory on your computer
$ scp -r username@dowithtech.its.india.ac.in:~/yourFolder ~/.

Downloading files from your home directory on the login node to your home directory on your local machine is a similar process using SSH private key as shown below:

# Download the file ~/yourFile.xyz to your home directory on your computer
$ scp -i "path_to_your_private_ssh_key" username@dowithtech.its.india.ac.in:~/yourFile.xyz ~/.
 
# Download the folder yourFolder to your home directory on your computer
$ scp -i "path_to_your_private_ssh_key" -r username@dowithtech.its.india.ac.in:~/yourFolder ~/.

I hope these commands will help you copy your files from/to your Linux VM. If you faced any issue, comment down below or you can get in touch with us through our Instagram page DoWithTech.

Readers also read: How to enable FTP on Ubuntu VM

Leave a Reply