Moving Files Between Linux Systems With SCP

Version 1.0
Author: Christian Schmalfeld  <c [dot] schmalfeld [at] projektfarm [dot] de>

This article is about how to move files between servers using the scp (secure copy) command. To show how it works, I will move files from my HDD to a virtual machine running on VirtualBox. There is Linux Mint 11 installed on both drives.

This tutorial comes without warranty of any kind. I do not guarantee that this will work for you.


1 Preliminary Note

Using scp you can not only move files to and between virtual machines like I will do, but move them to any server on the world as well. You only have to know that server's IP adress and the passwords needed to access it.


2 Configuring the Virtual Machine's System

To be able to send files to your virtual machines, you first need to have some specific configuration. Open VirtualBox, select the virtual machine you have your target system running on and open Settings > Network. Select the correct Adapter tab (the first one if you haven't done any changes yet) and select Bridged Adapter from the Attached to: dropdown menu. Run your virtual machine afterwards. Once started, open a terminal and enter

sudo apt-get install openssh-server

ifconfig will show you some blocks, one titled eth0.

[email protected] ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr f4:6d:04:94:8f:17
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::f66d:4ff:fe94:8f17/64 Scope:Link
          RX packets:234392 errors:0 dropped:0 overruns:0 frame:0
          TX packets:128835 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:332109021 (332.1 MB)  TX bytes:11758082 (11.7 MB)
          Interrupt:43 Base address:0x6000

lo        Link encap:Local Loopback
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2424 (2.4 KB)  TX bytes:2424 (2.4 KB)

[email protected] ~ $

The IP shown on inet adress: is the one your machine has in your internal network, it will be the one you are going to access the machine under. Go back to the sender system now that you know the receiver's IP. If you have the files to send and the directory to store them on your virtual machine ready, you can proceed by sending the files. Replace the items in [square brackets] with the actual data:

scp [path of file to send] [email protected][receiver's IP]:[target directory]

Here is what it looked like if I wanted to send the file FunnyVideo.mp4 in the /home/ctest/Videos directory to the /home/virtualguy/Videos directory of the system with the internal IP

scp /home/ctest/Videos/FunnyVideo.mp4 [email protected]:/home/virtualguy/Videos

It may happen that you receive following message having entered the scp command:

[email protected] ~ $ scp /home/ctest/Videos/FunnyVideo.mp4 [email protected]:/home/virtualguy/Videos
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /home/ctest/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/ctest/.ssh/known_hosts:4
  remove with: ssh-keygen -f "/home/ctest/.ssh/known_hosts" -R
ECDSA host key for has changed and you have requested strict checking.
Host key verification failed.
lost connection
[email protected] ~ $

This, in most cases, is caused by the fact that the system with the given IP is no longer the same system as it was when you last connected to the same IP, for example, if you hosted a new virtual machine that then took the same IP as the old one. To correct this issue, follow the commands given in the message to remove the offending key. In my case, it is:

ssh-keygen -f "/home/ctest/.ssh/known_hosts" -R

Make sure to replace the path and the IP with the ones matching your inputs. You can also remove the key manually by opening the known_hosts file with a texteditor and removing the key (as root, of course).

If no issue of that sort appears or you have dealt with it, you will be asked if you really want to proceed. Type in yes and hit Enter to confirm. You will then be asked for the receiver's root password. Type it in and hit Enter again. The copied file should then be accessible on the receiver's targeted directory, although you should not have any permissions to write or execute it. If you want to grant you full permissions, use

sudo chmod 777 /home/virtualguy/Videos/FunnyVideo.mp4

and make sure to change the path value to the one of your file.

Share this page:

Suggested articles

4 Comment(s)

Add comment


By: AndyMcD

A nice article, but you have included some very basic mistakes that need to be highlighted.

  1. You should not use the root account to transfer files.
  2. Setting the file permissions on any file to 777 is totally insecure. An MP4 file does not need to be executable at all.

By: Anonymous

This does actually copy the file.

By: Muhammad


I have two Virtual instances of Debian running. I see both have same IP address. So I can not copy from one machine to another one. if I use scp, It copies the file on the same machine. Any hint?


Best Regards,

By: VFRDavid

 The title of your article is "Moving Files Between Linux Systems With SCP" - however - this is "just" a copy - the original files remain in their original location and an additional copy of that file will now also exist in the destination location.  I am interested in actually MOVING files from one system to another - where the file would *only* exist in the new location.  Of course, I could run an "scp" command and then an "rm" command - but - I would have to somehow check that the copy was successful, before removing it from the source - which I think it part of the "move" commands in other operating systems (the remove doesn't occur if the copy didn't complete successfully, at least in theory).

Anyway - is there an "easy" way to do this?