How to transfer files with SCP command

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 scpto 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@

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 /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.

About Travis Newton 18 Articles
I am a Cloud Engineer currently working in the financial and web hosting industry. My passion has been Linux since I first discovered it in 2005. Throughout my career, I have always implemented Linux wherever possible and am an advocate of using open source software over proprietary whenever possible. I strongly believe in the UNIX philosophy of "Do One Thing and Do It Well". I started The Linux Lab as a way for people to discover Linux (and UNIX in general, even macOS users) and to find solutions to problems and learn about Linux.

Be the first to comment

Leave a Reply

Your email address will not be published.