When you’re working with systems, you’re going to end up needing to transfer files between your system and a remote system or even two remote systems. Unix systems have this really great program installed by default called scp
which stands for secure copy. This is a handy program which lets you transfer files or a complete directory:
- from your local system to a remote system
- from a remote system to your local system
- between two remote systems
For instance, lets say that I have a 250 MB tar archive I want to move between two servers. Instead of downloading that file to my system and then uploading it again to the other server, I can use scp
to transfer it between both systems from my remote system.
SCP Syntax
scp
is very easy to use and has some very straight forward syntax:
scp [OPTIONS] [[user@]SRC_HOST:]file1 [[user@]DEST_HOST:]file2
- OPTIONS – scp options such as cipher, ssh configuration/port, limit, recursive copy, identity file, etc.
- [[user@]SRC_HOST:]file1 – the file/directory you want to copy
- [[user@]DEST_HOST:]file2 – the receiving host and the file/directory name
Before you copy
scp uses ssh to transfer data across the network. That means in order to copy the data to the other system, you need to have ssh access – either through a username and password or a username and public/private key. It’s also important to know that the colon is how systems are distinguished by scp.
Copying a file between two systems
This is primarily how I use scp. I work with a lot of virtual hosts and occasionally an ISO image is available on one host but not the other. To send it to the other host, I use the following:
scp centos7.iso root@10.19.42.37:/var/lib/vz/template/iso/centos7.iso
centos7.iso is the file on the current system where I am currently located. This is the file I want to copy to the remote system. I am connecting to the other system as the root user. The other system’s IP address is 10.19.42.37. /var/lib/vz/template/iso is the directory structure where I am placing the file. centos7.iso is the file name on the remote system I am writing to.
When you run the command, you’ll be prompted for the password.