Secure remote file copy

Here’s a quick description of the scp command used for securely copying files between systems on Linux and UNIX.

The scp (secure copy) command can be used to copy files or even entire directories to a remote host. scp is a replacement for the rcp (remote copy) command. While rcp provides the same functionality it is not encrypted and therefore not secure. The scp command uses SSH for data transfer, providing SSH level security.

scp takes arguments in the form of scp –options source destination. The most common option is the –r (recursive) option which is necessary if you are using scp on multiple files or on directories. The source and destination arguments can specify not only a path but optionally a username and hostname in the format of username@hostname:path. If the username is omitted scp assumes the username of the current logged in user. If the hostname is omitted scp assumes the path provided is on the current system. Typically either the source or the destination will describe a remote system; however you could use scp to move a file or files from one remote system to another.

The following example copies the file secret.dat from user tclark’s home directory to a directory named /backup/tclark on a server named backup_server logging in as user terry. As indicated below, the scp command will prompt for the password for user terry on the backup_server when the connection is attempted.

$ scp /home/tclark/secret.dat terry@backup_server:/backup/tclark
terry@backup_server's password: password
secret.dat 100% 1011 27.6KB/s 00:00

Zach has a good article about setting up ssh with key authentication which will allow you to use the scp and ssh commands without a password while still maintaining security.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


linux, unix, system administration, sysadmin, easy linux, scp

4 thoughts on “Secure remote file copy”

  1. We use this where I work. We have public key/private key authentication setup so I can copy from any Oracle server to any other Oracle server as the Oracle user without specifying a password. It makes it much easier to keep to remote shell scripts in sync.

  2. >>Typically either the source or the destination will describe a remote system; however you could use scp to move a file or files from one remote system to another.

    I don’t think you can “move” files with scp, only copy.

  3. It would appear from the list of incoming searches, many people are coming here looking for a “move” command to be used with scp. (Like me.)
    Unfortunately this is not covered in this article, and I would like to request that you remove the “move” test from the article so Google and Yahoo don’t keep leading people to the wrong info.
    Also, please delete my messages as they also contain the word “move” which should not be indexed with this article.
    Thanks,
    John

Leave a Reply

Your email address will not be published. Required fields are marked *