Moving Files Between Linux Systems With SCP
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:192.168.0.11 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::f66d:4ff:fe94:8f17/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:234392 errors:0 dropped:0 overruns:0 frame:0
TX packets:128835 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:332109021 (332.1 MB) TX bytes:11758082 (11.7 MB)
Interrupt:43 Base address:0x6000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
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
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 192.168.0.11:
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]test-System-Product-Name ~ $ scp /home/ctest/Videos/FunnyVideo.mp4 [email protected]:/home/virtualguy/Videos
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
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 192.168.0.11
ECDSA host key for 192.168.0.11 has changed and you have requested strict checking.
Host key verification failed.
[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 192.168.0.11
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.